.mx-page {
  max-width: 1540px;
  margin: 0 auto;
  padding: 0 18px 22px;
  height: calc(100dvh - 84px);
  min-height: 0;
}

.mx-shell {
  --mx-sidebar-width: 460px;
  display: grid;
  grid-template-columns: minmax(380px, var(--mx-sidebar-width)) 8px minmax(0, 1fr);
  column-gap: 14px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.mx-sidebar,
.mx-main {
  background: var(--rd-surface);
  color: var(--rd-text);
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
}

.mx-sidebar {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  min-height: 0;
  max-height: 100%;
}

.mx-sidebar-content {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--rd-border);
}

.mx-sidebar-head,
.mx-thread-head,
.mx-composer {
  padding: 7px 9px;
}

.mx-sidebar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.mx-sidebar-head-actions {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: nowrap;
}

.mx-sidebar-head-actions-desktop {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.mx-mobile-compose-wrap {
  position: relative;
  display: none;
}

.mx-sidebar-icon-btn,
.mx-sidebar-search-close {
  width: 38px;
  height: 38px;
  min-width: 38px;
  padding: 0;
  border: 1px solid var(--rd-border);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--rd-bg);
  color: var(--rd-link);
  cursor: pointer;
}

.mx-sidebar-icon-btn:hover,
.mx-sidebar-search-close:hover,
.mx-sidebar-icon-btn[aria-expanded="true"] {
  border-color: rgba(37, 99, 235, 0.35);
  background: var(--rd-hover);
}

.mx-sidebar-icon-btn.is-primary {
  border-color: transparent;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
}

.mx-sidebar-search-overlay {
  position: absolute;
  z-index: 45;
  top: 0;
  left: 0;
  right: 0;
  padding: 9px;
  display: grid;
  gap: 6px;
  background: var(--rd-surface);
  background: color-mix(in srgb, var(--rd-surface) 96%, transparent);
  border-bottom: 1px solid var(--rd-border);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
  backdrop-filter: blur(12px);
}

.mx-sidebar-search-overlay[hidden],
.mx-sidebar-action-menu[hidden] {
  display: none;
}

.mx-sidebar-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
}

.mx-sidebar-search-overlay .mx-search-field {
  min-height: 40px;
  background: var(--rd-surface);
}

.mx-sidebar-action-menu {
  position: absolute;
  z-index: 80;
  top: calc(100% + 7px);
  right: 0;
  width: max-content;
  min-width: 190px;
  padding: 6px;
  border: 1px solid var(--rd-border);
  border-radius: 10px;
  display: grid;
  gap: 3px;
  background: var(--rd-surface);
  box-shadow: 0 16px 38px rgba(15, 23, 42, 0.2);
}

.mx-sidebar-action-menu button {
  min-height: 40px;
  padding: 0 11px;
  border: 0;
  border-radius: 7px;
  display: flex;
  align-items: center;
  gap: 9px;
  background: transparent;
  color: var(--rd-text);
  text-align: left;
  cursor: pointer;
}

.mx-sidebar-action-menu button:hover,
.mx-sidebar-action-menu button:focus-visible {
  background: var(--rd-hover);
  outline: none;
}

.mx-sidebar-head-copy {
  min-width: 0;
}

.mx-sidebar-caption {
  margin-top: 6px;
  color: var(--rd-muted);
  font-size: 0.84rem;
}

.mx-sidebar-head h1,
.mx-thread-head h2,
.mx-empty-hero h2,
.mx-modal-head h2 {
  margin: 0;
  color: var(--rd-text);
}

.mx-sidebar-head p,
.mx-thread-head p,
.mx-empty-hero p,
.mx-modal-head p {
  margin: 6px 0 0;
  color: var(--rd-muted);
}

.mx-sidebar-tools {
  padding: 0 6px 6px;
  display: grid;
  gap: 6px;
}

.mx-search-field {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 10px;
  border-radius: 6px;
  background: var(--rd-bg);
  border: 1px solid var(--rd-border);
  color: var(--rd-muted);
}

.mx-search-field i {
  font-size: 0.9rem;
}

.mx-search-field input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--rd-text);
}

.mx-search-field input::placeholder {
  color: var(--rd-muted);
}

.mx-search-select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  background: var(--rd-bg);
  color: var(--rd-text);
  padding: 0 10px;
}

.mx-new-dialog-btn,
.mx-modal-close,
.mx-attach-btn,
.mx-emoji-btn,
.mx-send-btn {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  border-radius: 6px;
  font-weight: 650;
  border: none;
  text-decoration: none;
}

.mx-new-dialog-btn {
  background: var(--rd-hover);
  color: var(--rd-link);
  flex-shrink: 0;
  max-width: 100%;
  white-space: normal;
  text-align: center;
  line-height: 1.2;
}

.mx-modal-close {
  width: 38px;
  padding: 0;
  background: var(--rd-bg);
  color: var(--rd-muted);
}

.mx-conversation-list {
  padding: 0 6px 6px;
  display: grid;
  gap: 6px;
  overflow: auto;
  min-height: 0;
  grid-auto-rows: max-content;
  align-content: start;
  overscroll-behavior: contain;
  flex: 1 1 auto;
}

.mx-folder-rail {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 7px 6px;
  background: var(--rd-bg);
  background: color-mix(in srgb, var(--rd-bg) 72%, var(--rd-surface));
}

.mx-folder-rail-scroll {
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  align-content: start;
  gap: 7px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0 1px 6px;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.mx-folder-rail-section {
  display: grid;
  gap: 6px;
}

.mx-folder-rail-divider {
  height: 1px;
  margin: 1px 8px;
  background: var(--rd-border);
}

.mx-folder-tab-wrap {
  position: relative;
  min-width: 0;
}

.mx-folder-tab {
  width: 100%;
  min-height: 62px;
  padding: 7px 4px;
  border: 1px solid var(--rd-border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: var(--rd-bg);
  color: var(--rd-text);
  font-size: 0.68rem;
  font-weight: 650;
  line-height: 1.08;
  text-decoration: none;
  text-align: center;
  overflow: hidden;
}

.mx-folder-tab i {
  font-size: 1rem;
  color: var(--rd-link);
}

.mx-folder-tab span {
  width: 100%;
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.mx-folder-tab:hover {
  background: var(--rd-hover);
  color: var(--rd-text);
  text-decoration: none;
}

.mx-folder-tab.is-active {
  border-color: var(--rd-accent);
  background: var(--rd-accent);
  color: #fff;
}

.mx-folder-tab.is-active i {
  color: #fff;
}

.mx-folder-tab.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.mx-folder-create-trigger {
  width: 100%;
  min-height: 58px;
  margin-top: 6px;
  padding: 7px 3px;
  border: 1px dashed var(--rd-border);
  border-color: color-mix(in srgb, var(--rd-accent) 58%, var(--rd-border));
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: transparent;
  color: var(--rd-link);
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
}

.mx-folder-create-trigger:hover,
.mx-folder-create-trigger[aria-expanded="true"] {
  background: var(--rd-hover);
  border-style: solid;
}

.mx-folder-edit-trigger {
  position: absolute;
  z-index: 2;
  top: 4px;
  right: 4px;
  width: 23px;
  height: 23px;
  padding: 0;
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: var(--rd-surface);
  color: var(--rd-muted);
  cursor: pointer;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.15s ease, transform 0.15s ease, color 0.15s ease;
}

.mx-folder-tab-wrap:hover .mx-folder-edit-trigger,
.mx-folder-edit-trigger:focus-visible,
.mx-folder-tab-wrap:focus-within .mx-folder-edit-trigger {
  opacity: 1;
  transform: translateY(0);
}

.mx-folder-edit-trigger:hover {
  color: var(--rd-link);
}

.mx-folder-edit-trigger i {
  font-size: 0.65rem;
}

.mx-folder-create-error {
  color: #dc2626;
  font-size: 0.76rem;
  line-height: 1.3;
}

.mx-folder-editor.mx-modal-card-wide {
  width: min(760px, calc(100vw - 24px));
  max-height: min(88vh, 820px);
}

.mx-folder-editor-form {
  min-height: 0;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
}

.mx-folder-editor .mx-modal-body {
  min-height: 0;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  overflow: hidden;
}

.mx-folder-editor-name {
  display: grid;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 750;
}

.mx-folder-editor-name input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--rd-border);
  border-radius: 7px;
  outline: none;
  background: var(--rd-bg);
  color: var(--rd-text);
}

.mx-folder-editor-name input:focus {
  border-color: var(--rd-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.mx-folder-editor-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.mx-folder-editor-filters {
  display: flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--rd-border);
  border-radius: 7px;
  background: var(--rd-bg);
}

.mx-folder-editor-filters button {
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--rd-muted);
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.mx-folder-editor-filters button:hover,
.mx-folder-editor-filters button.is-active {
  background: var(--rd-hover);
  color: var(--rd-link);
}

.mx-folder-editor-list {
  min-height: 220px;
  flex: 1 1 auto;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 2px;
  scrollbar-width: thin;
}

.mx-folder-editor-list[hidden] {
  display: none;
}

.mx-folder-editor-item {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 28px;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 7px 10px;
  border: 1px solid var(--rd-border);
  border-radius: 8px;
  background: var(--rd-surface);
  cursor: pointer;
}

.mx-folder-editor-item:hover {
  background: var(--rd-hover);
}

.mx-folder-editor-item.is-selected {
  border-color: var(--rd-accent);
  background: var(--rd-hover);
  background: color-mix(in srgb, var(--rd-accent) 8%, var(--rd-surface));
}

.mx-folder-editor-item > input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.mx-folder-editor-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--rd-hover);
  color: var(--rd-link);
  font-size: 0.76rem;
  font-weight: 800;
}

.mx-folder-editor-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mx-folder-editor-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.mx-folder-editor-copy strong,
.mx-folder-editor-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mx-folder-editor-copy strong {
  font-size: 0.86rem;
}

.mx-folder-editor-copy span {
  color: var(--rd-muted);
  font-size: 0.74rem;
}

.mx-folder-editor-check {
  width: 25px;
  height: 25px;
  border: 1px solid var(--rd-border);
  border-radius: 7px;
  display: grid;
  place-items: center;
  color: transparent;
  font-size: 0.7rem;
}

.mx-folder-editor-item.is-selected .mx-folder-editor-check {
  border-color: var(--rd-accent);
  background: var(--rd-accent);
  color: #fff;
}

.mx-folder-editor-status {
  min-height: 220px;
  flex: 1 1 auto;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  color: var(--rd-muted);
  text-align: center;
}

.mx-folder-editor-status[hidden] {
  display: none;
}

.mx-folder-editor-footer {
  min-height: 58px;
  padding: 10px 12px;
  border-top: 1px solid var(--rd-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--rd-muted);
  font-size: 0.78rem;
}

.mx-folder-editor-actions {
  display: flex;
  gap: 8px;
}

.mx-sidebar-resizer {
  position: relative;
  z-index: 12;
  width: 8px;
  min-width: 8px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
  border-radius: 999px;
  outline: none;
}

.mx-sidebar-resizer::before {
  content: "";
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: 3px;
  width: 2px;
  border-radius: inherit;
  background: var(--rd-border);
  transition: width 140ms ease, left 140ms ease, background 140ms ease;
}

.mx-sidebar-resizer:hover::before,
.mx-sidebar-resizer:focus-visible::before,
.mx-is-resizing-sidebar .mx-sidebar-resizer::before {
  left: 2px;
  width: 4px;
  background: var(--rd-accent);
}

body.mx-is-resizing-sidebar {
  cursor: col-resize;
  user-select: none;
}

.mx-conversation-item {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 9px;
  padding: 7px;
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
  border: 1px solid transparent;
  background: var(--rd-bg);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.mx-conversation-item.is-hidden {
  display: none;
}

.mx-conversation-avatar,
.mx-thread-avatar-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mx-avatar-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.mx-conversation-copy {
  min-width: 0;
  display: block;
  color: inherit;
  text-decoration: none;
}

.mx-conversation-copy:hover {
  text-decoration: none;
  color: inherit;
}

.mx-conversation-copy.is-disabled {
  cursor: default;
  opacity: 0.8;
}

.mx-conversation-favorite {
  width: 32px;
  height: 32px;
  align-self: center;
  border: 0;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--rd-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.mx-conversation-favorite:hover {
  background: rgba(245, 158, 11, 0.12);
  color: #d97706;
}

.mx-conversation-favorite.is-active {
  background: rgba(245, 158, 11, 0.14);
  color: #d97706;
}

.mx-conversation-item:hover {
  border-color: var(--rd-border);
  background: var(--rd-hover);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.05);
}

.mx-conversation-item:has(.mx-conversation-copy.is-disabled):hover {
  background: transparent;
  box-shadow: none;
  transform: none;
}

.mx-conversation-item.is-active {
  background: var(--rd-hover);
  border-color: var(--rd-accent);
}

.mx-conversation-item.is-unread strong {
  color: var(--rd-link);
}

/* Global search: message hit (before chat rows) */
.mx-conversation-item.is-search-message {
  border-left: 3px solid var(--rd-accent, #6366f1);
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.06), transparent 48%);
}

.mx-conversation-item.is-search-message .mx-row-badge {
  background: rgba(99, 102, 241, 0.12);
  color: #4338ca;
}

.mx-avatar {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  overflow: hidden;
  flex-shrink: 0;
}

.mx-avatar.lg {
  width: 50px;
  height: 50px;
  border-radius: 6px;
  font-size: 18px;
}

.mx-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.mx-conversation-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.mx-conversation-title {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.mx-conversation-title strong {
  color: var(--rd-text);
  font-size: 0.95rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mx-unread-pill {
  min-width: 20px;
  height: 20px;
  border-radius: 6px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--rd-accent);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.mx-conversation-item.is-muted .mx-unread-pill {
  background: #94a3b8;
  color: #fff;
}

.mx-conversation-muted-icon {
  flex: 0 0 auto;
  color: #94a3b8;
  font-size: 0.72rem;
}

.mx-presence-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--rd-border);
  box-shadow: 0 0 0 2px var(--rd-surface);
  flex-shrink: 0;
}

.mx-presence-dot.is-online {
  background: var(--rd-success);
}

.mx-conversation-preview {
  margin-top: 4px;
  color: var(--rd-muted);
  font-size: 0.82rem;
  line-height: 1.35;
  /* Однострочное превью с многоточием — длинное сообщение/«N вложений»
     больше не ломает высоту и ширину плашки чата. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mx-main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

.mx-main-empty {
  align-items: center;
  justify-content: center;
}

.mx-empty,
.mx-empty-hero {
  color: var(--rd-muted);
  text-align: center;
}

.mx-empty {
  padding: 20px 14px;
}

.mx-empty-hero {
  padding: 24px 20px;
}

.mx-empty-hero.compact {
  padding: 16px 0;
}

.mx-empty i,
.mx-empty-hero i {
  font-size: 30px;
  color: var(--rd-muted);
  margin-bottom: 12px;
}

.mx-mobile-back {
  display: none;
}

.mx-thread-head {
  border-bottom: 1px solid var(--rd-border);
}

.mx-thread-search-panel {
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--rd-border);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px auto;
  gap: 8px;
  align-items: start;
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.04), transparent);
}

.mx-thread-search-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--rd-bg);
  color: var(--rd-muted);
  cursor: pointer;
}

.mx-thread-search-results {
  grid-column: 1 / -1;
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}

.mx-thread-search-result {
  width: 100%;
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  padding: 8px 10px;
  display: grid;
  gap: 4px;
  background: var(--rd-surface);
  color: var(--rd-text);
  cursor: pointer;
  text-align: left;
}

.mx-thread-search-result:hover {
  background: var(--rd-hover);
}

.mx-thread-search-result-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mx-thread-search-result-top time {
  color: var(--rd-muted);
  font-size: 0.78rem;
  flex-shrink: 0;
}

.mx-thread-search-result-preview {
  color: var(--rd-muted);
  font-size: 0.84rem;
  line-height: 1.35;
  word-break: break-word;
}

.mx-thread-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mx-thread-user-copy {
  min-width: 0;
}

.mx-thread-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  color: var(--rd-muted);
  font-size: 0.9rem;
}

.mx-thread-stream {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 0;
  padding: 16px 18px;
  display: grid;
  gap: 10px;
  background:
    radial-gradient(circle at top, rgba(37, 99, 235, 0.06), transparent 42%),
    linear-gradient(180deg, var(--rd-bg), var(--rd-surface));
}

.mx-thread-window-loader {
  position: absolute;
  top: 86px;
  left: 50%;
  z-index: 12;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border: 1px solid var(--rd-border);
  border-radius: 999px;
  background: var(--rd-surface);
  color: var(--rd-muted);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.12);
  font-size: 0.78rem;
}

.mx-thread-window-loader[hidden],
.mx-return-latest[hidden],
.mx-readers-popover[hidden] {
  display: none;
}

.mx-return-latest {
  position: absolute;
  right: 22px;
  bottom: 92px;
  z-index: 14;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 13px;
  border: 1px solid rgba(37, 99, 235, 0.24);
  border-radius: 999px;
  background: var(--rd-surface);
  color: var(--rd-primary);
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.16);
  font-weight: 700;
  cursor: pointer;
}

.mx-return-latest:hover {
  background: var(--rd-primary-soft);
}

.mx-message {
  display: flex;
  align-items: flex-end;
}

.mx-message.is-own {
  justify-content: flex-end;
}

.mx-message-bubble {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  width: fit-content;
  max-width: min(70ch, 77%);
  min-width: 0;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--rd-surface);
  color: var(--rd-text);
  border: 1px solid var(--rd-border);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
}

.mx-message-reply-trigger {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--rd-surface);
  color: var(--rd-muted);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.14);
  cursor: pointer;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 160ms ease, transform 160ms ease, background 160ms ease;
}

.mx-message:hover .mx-message-reply-trigger,
.mx-message-reply-trigger:focus-visible {
  opacity: 1;
  transform: translateY(0);
}

.mx-message.is-own .mx-message-reply-trigger {
  background: rgba(15, 23, 42, 0.42);
  color: rgba(255, 255, 255, 0.95);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(4px);
}

.mx-message-reply-trigger:hover {
  background: rgba(37, 99, 235, 0.12);
  color: var(--rd-link);
}

.mx-message.is-own .mx-message-reply-trigger:hover {
  background: rgba(255, 255, 255, 0.24);
  color: #ffffff;
}

.mx-message-reply {
  width: 100%;
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 0;
  border-left: 3px solid var(--rd-link);
  border-radius: 6px;
  display: grid;
  gap: 3px;
  background: rgba(37, 99, 235, 0.08);
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.mx-message.is-own .mx-message-reply {
  border-left-color: rgba(255, 255, 255, 0.94);
  background: rgba(255, 255, 255, 0.16);
}

.mx-message-reply-author {
  font-size: 0.75rem;
  font-weight: 700;
}

.mx-message-reply-text {
  font-size: 0.82rem;
  opacity: 0.82;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mx-message.is-own .mx-message-bubble {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
}

.mx-message-text {
  line-height: 1.6;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  max-width: 100%;
}

.mx-message-text.is-format-markdown,
.mx-message-text.is-format-html {
  white-space: normal;
}

.mx-message-text p,
.mx-message-text ul,
.mx-message-text ol,
.mx-message-text blockquote,
.mx-message-text pre,
.mx-message-text table {
  margin: 0 0 0.65em;
}

.mx-message-text > :last-child {
  margin-bottom: 0;
}

.mx-message-text code {
  padding: 0.12em 0.34em;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.1);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.mx-message-text pre {
  max-width: 100%;
  padding: 9px 10px;
  overflow-x: auto;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.12);
}

.mx-message-text pre code {
  padding: 0;
  background: transparent;
}

.mx-message-text a {
  color: inherit;
  font-weight: 650;
  text-decoration: underline;
}

.mx-message-text table {
  max-width: 100%;
  border-collapse: collapse;
}

.mx-message-text th,
.mx-message-text td {
  padding: 4px 7px;
  border: 1px solid currentColor;
}

.mx-message-reactions {
  width: 100%;
  margin-top: 7px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.mx-message-reactions[hidden] {
  display: none;
}

.mx-reaction-chip {
  --mx-reaction-color: var(--rd-muted);
  min-width: 34px;
  min-height: 27px;
  padding: 4px 8px;
  border: 1px solid var(--rd-border);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: rgba(148, 163, 184, 0.1);
  color: var(--rd-muted);
  cursor: pointer;
  font-size: 0.78rem;
}

.mx-reaction-chip i,
.mx-context-reaction-grid button i {
  color: var(--mx-reaction-color);
}

.mx-reaction-chip[data-reaction-key="like"],
.mx-context-reaction-grid button[data-context-reaction="like"] { --mx-reaction-color: #2563eb; }
.mx-reaction-chip[data-reaction-key="love"],
.mx-context-reaction-grid button[data-context-reaction="love"] { --mx-reaction-color: #e11d48; }
.mx-reaction-chip[data-reaction-key="laugh"],
.mx-context-reaction-grid button[data-context-reaction="laugh"] { --mx-reaction-color: #f59e0b; }
.mx-reaction-chip[data-reaction-key="wow"],
.mx-context-reaction-grid button[data-context-reaction="wow"] { --mx-reaction-color: #8b5cf6; }
.mx-reaction-chip[data-reaction-key="sad"],
.mx-context-reaction-grid button[data-context-reaction="sad"] { --mx-reaction-color: #0ea5e9; }
.mx-reaction-chip[data-reaction-key="angry"],
.mx-context-reaction-grid button[data-context-reaction="angry"] { --mx-reaction-color: #dc2626; }
.mx-reaction-chip[data-reaction-key="fire"],
.mx-context-reaction-grid button[data-context-reaction="fire"] { --mx-reaction-color: #f97316; }
.mx-reaction-chip[data-reaction-key="star"],
.mx-context-reaction-grid button[data-context-reaction="star"] { --mx-reaction-color: #eab308; }

.mx-reaction-chip.is-active {
  border-color: rgba(37, 99, 235, 0.48);
  background: rgba(37, 99, 235, 0.14);
  color: var(--rd-link);
}

.mx-message.is-own .mx-reaction-chip {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.86);
}

.mx-message.is-own .mx-reaction-chip.is-active {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

.mx-attachments {
  position: relative;
  z-index: 1;
  margin-top: 10px;
  display: grid;
  gap: 6px;
  width: 100%;
  /* Не даём вложениям (особенно файл-карточкам) распирать пузырь во всю
     ширину на десктопе. Image-tile (280px) меньше кэпа — превью не страдает. */
  max-width: 340px;
}

/* Только вложения (без текста) — место под кнопку «Ответить» */
.mx-message-bubble:has(.mx-attachments):not(:has(.mx-message-text)) {
  padding-top: 36px;
}

.mx-attachment-tile {
  width: min(280px, 100%);
  max-width: 100%;
  box-sizing: border-box;
  padding: 0;
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--rd-surface);
  color: inherit;
  cursor: pointer;
  text-align: left;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.mx-message.is-own .mx-attachment-tile {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.12);
}

.mx-attachment-media {
  position: relative;
  aspect-ratio: 16 / 10;
  background:
    radial-gradient(circle at top, rgba(37, 99, 235, 0.16), transparent 48%),
    rgba(15, 23, 42, 0.92);
  overflow: hidden;
}

.mx-attachment-media img,
.mx-attachment-media video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.mx-attachment-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 2rem;
  text-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.mx-attachment-caption {
  padding: 8px 10px;
  display: grid;
  gap: 3px;
}

.mx-attachment-name {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mx-attachment-size {
  font-size: 0.8rem;
  color: var(--rd-muted);
}

.mx-message.is-own .mx-attachment-size {
  color: rgba(255, 255, 255, 0.74);
}

.mx-attachment-file-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  background: var(--rd-bg);
  max-width: 100%;
  box-sizing: border-box;
}

.mx-message.is-own .mx-attachment-file-card {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.12);
}

.mx-attachment-file-card.is-deleted {
  grid-template-columns: auto minmax(0, 1fr);
  border-style: dashed;
  background: rgba(100, 116, 139, 0.08);
}

.mx-message.is-own .mx-attachment-file-card.is-deleted {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
}

.mx-attachment-file-icon {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(37, 99, 235, 0.1);
  color: var(--rd-link);
  font-size: 1.1rem;
}

.mx-attachment-file-card.is-deleted .mx-attachment-file-icon {
  background: rgba(148, 163, 184, 0.16);
  color: var(--rd-muted);
}

.mx-message.is-own .mx-attachment-file-card.is-deleted .mx-attachment-file-icon {
  background: rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.86);
}

.mx-attachment-file-card.is-deleted .mx-attachment-file-name {
  position: relative;
  color: transparent;
}

.mx-attachment-file-card.is-deleted .mx-attachment-file-name::before {
  content: "\0423\0434\0430\043b\0451\043d\043d\044b\0439 \0444\0430\0439\043b";
  position: absolute;
  inset: 0 auto auto 0;
  color: var(--rd-text);
}

.mx-message.is-own .mx-attachment-file-card.is-deleted .mx-attachment-file-name::before {
  color: #ffffff;
}

.mx-attachment-file-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.mx-attachment-file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.mx-attachment-file-meta {
  font-size: 0.8rem;
  color: var(--rd-muted);
}

.mx-message.is-own .mx-attachment-file-meta {
  color: rgba(255, 255, 255, 0.74);
}

.mx-attachment-file-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.mx-attachment-file-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 6px;
  background: rgba(37, 99, 235, 0.12);
  color: var(--rd-link);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}

.mx-message.is-own .mx-attachment-file-action {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.mx-attachment-file-action:hover {
  text-decoration: none;
  filter: brightness(0.98);
}

.mx-message-meta {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  width: 100%;
  font-size: 0.76rem;
  color: var(--rd-muted);
}

.mx-message-meta > :first-child {
  margin-right: auto;
}

.mx-message.is-own .mx-message-meta {
  color: rgba(255, 255, 255, 0.78);
}

.mx-message-edited {
  font-weight: 600;
  letter-spacing: 0.01em;
}

.mx-message-read-count {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  border-radius: 4px;
}

.mx-message-read-count:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.mx-message-read-count i {
  font-size: 0.72rem;
}

.mx-readers-popover {
  position: fixed;
  z-index: 1700;
  width: min(280px, calc(100vw - 16px));
  max-height: min(340px, calc(100vh - 24px));
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--rd-border);
  border-radius: 10px;
  background: var(--rd-surface);
  color: var(--rd-text);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.2);
}

.mx-reader-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px;
  border-radius: 7px;
}

.mx-reader-row + .mx-reader-row {
  margin-top: 2px;
}

.mx-reader-avatar {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  object-fit: cover;
  background: var(--rd-primary-soft);
  color: var(--rd-primary);
  font-size: 0.7rem;
  font-weight: 800;
}

.mx-reader-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.mx-reader-copy strong,
.mx-reader-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mx-reader-copy small,
.mx-readers-empty,
.mx-readers-more {
  color: var(--rd-muted);
  font-size: 0.76rem;
}

.mx-readers-empty,
.mx-readers-more {
  padding: 7px 8px;
}

.mx-message.is-flash .mx-message-bubble {
  animation: mx-message-flash 1.2s ease;
}

@keyframes mx-message-flash {
  0% {
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.28);
  }
  55% {
    box-shadow: 0 0 0 10px rgba(37, 99, 235, 0.08);
  }
  100% {
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
  }
}

.mx-composer {
  border-top: 1px solid var(--rd-border);
  display: grid;
  gap: 8px;
  position: relative;
  z-index: 20;
  overflow: visible;
}

.mx-edit-bar,
.mx-reply-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--rd-border);
  border-radius: 6px;
}

.mx-edit-bar {
  border-color: rgba(245, 158, 11, 0.26);
  background: rgba(245, 158, 11, 0.08);
}

.mx-reply-bar {
  background: var(--rd-hover);
}

.mx-edit-bar-copy,
.mx-reply-bar-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.mx-edit-bar-label,
.mx-reply-bar-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--rd-muted);
}

.mx-edit-bar-preview,
.mx-reply-bar-preview {
  color: var(--rd-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mx-edit-bar-close,
.mx-reply-bar-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--rd-muted);
  cursor: pointer;
}

.mx-edit-bar-close:hover,
.mx-reply-bar-close:hover {
  background: rgba(148, 163, 184, 0.12);
  color: var(--rd-text);
}

.mx-composer textarea {
  width: 100%;
  /* База — 1 строка, максимум ~4 строки, дальше скролл (авто-рост в JS) */
  min-height: 40px;
  max-height: 116px;
  line-height: 1.4;
  resize: none;
  overflow-y: auto;
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  padding: 9px 12px;
  outline: none;
  background: var(--rd-bg);
  color: var(--rd-text);
}

.mx-composer textarea::placeholder {
  color: var(--rd-muted);
}

/* Контейнер ввода. Десктоп: textarea на всю ширину сверху, действия снизу. */
.mx-composer-main {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 10px;
}
.mx-composer-main #mxComposerBody { flex: 1 1 100%; order: 0; }

.mx-attach-btn {
  order: 1;
  flex-shrink: 0;
  background: var(--rd-hover);
  color: var(--rd-link);
  cursor: pointer;
  margin: 0;
}

.mx-attach-btn.is-disabled {
  opacity: 0.58;
  cursor: not-allowed;
  pointer-events: none;
}

.mx-attach-note {
  order: 2;
  flex: 1 1 auto;
  color: var(--rd-muted);
  font-size: 0.84rem;
}

.mx-composer-submit-actions {
  order: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.mx-format-select {
  order: 2;
  min-height: 40px;
  padding: 0 8px;
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--rd-bg);
  color: var(--rd-muted);
}

.mx-format-select select {
  max-width: 104px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--rd-text);
  font: inherit;
  font-size: 0.78rem;
}

.mx-emoji-picker {
  position: relative;
  flex-shrink: 0;
}

.mx-emoji-btn {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid rgba(245, 158, 11, 0.28);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #ffffff 0, #fff8dc 42%, #ffedaa 100%);
  color: #92400e;
  box-shadow: 0 3px 10px rgba(180, 83, 9, 0.13);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.mx-emoji-btn:hover,
.mx-emoji-btn[aria-expanded="true"] {
  border-color: rgba(245, 158, 11, 0.55);
  background: radial-gradient(circle at 35% 28%, #ffffff 0, #fff3c4 42%, #ffe27a 100%);
  box-shadow: 0 6px 16px rgba(180, 83, 9, 0.2);
  transform: translateY(-1px);
}

.mx-emoji-btn:active {
  transform: translateY(0) scale(0.96);
}

.mx-emoji-btn:focus-visible {
  outline: 3px solid rgba(245, 158, 11, 0.24);
  outline-offset: 2px;
}

.mx-emoji-glyph {
  display: block;
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-size: 1.3rem;
  line-height: 1;
  filter: saturate(1.08);
}

.mx-emoji-menu {
  position: absolute;
  right: 0;
  left: auto;
  bottom: calc(100% + 8px);
  z-index: 1500;
  width: min(304px, calc(100vw - 32px));
  max-height: 232px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--rd-border);
  border-radius: 16px;
  background: var(--rd-surface);
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.2);
}

.mx-emoji-menu[hidden] {
  display: none;
}

.mx-emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(28px, 1fr));
  gap: 3px;
}

.mx-emoji-option {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font-size: 1.18rem;
  line-height: 1;
}

.mx-emoji-option:hover,
.mx-emoji-option:focus-visible {
  background: var(--rd-hover);
  outline: none;
}

.mx-send-btn {
  order: 4;
  flex-shrink: 0;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
}

.mx-context-menu {
  position: fixed;
  z-index: 1450;
  min-width: 180px;
  padding: 8px;
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  background: var(--rd-surface);
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.18);
}

.mx-context-reactions {
  padding: 2px 2px 7px;
  margin-bottom: 5px;
  border-bottom: 1px solid var(--rd-border);
}

.mx-context-reactions[hidden] {
  display: none;
}

.mx-context-section-label {
  padding: 2px 4px 6px;
  color: var(--rd-muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.mx-context-reaction-grid {
  display: grid;
  grid-template-columns: repeat(4, 36px);
  gap: 4px;
}

.mx-context-reaction-grid button {
  --mx-reaction-color: var(--rd-muted);
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--rd-muted);
  cursor: pointer;
}

.mx-context-reaction-grid button:hover,
.mx-context-reaction-grid button:focus-visible,
.mx-context-reaction-grid button.is-active {
  background: rgba(37, 99, 235, 0.13);
  color: var(--rd-link);
  outline: none;
}

.mx-context-menu[hidden] {
  display: none;
}

.mx-context-menu-item {
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  color: var(--rd-text);
  cursor: pointer;
  text-align: left;
}

.mx-context-menu-item:hover {
  background: var(--rd-hover);
}

.mx-context-menu-item.is-danger {
  color: #dc2626;
}

.mx-context-menu-item.is-danger:hover {
  background: rgba(220, 38, 38, 0.1);
  color: #b91c1c;
}

.mx-media-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(2, 6, 23, 0.76);
  backdrop-filter: blur(8px);
}

.mx-media-lightbox[hidden] {
  display: none;
}

.mx-media-lightbox-dialog {
  width: min(1100px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  overflow: hidden;
  background: rgba(15, 23, 42, 0.94);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.mx-media-lightbox-stage {
  min-height: min(72vh, 760px);
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at top, rgba(37, 99, 235, 0.18), transparent 36%),
    rgba(2, 6, 23, 0.96);
}

.mx-media-lightbox-stage img,
.mx-media-lightbox-stage video {
  max-width: 100%;
  max-height: min(72vh, 760px);
  display: block;
}

.mx-media-lightbox-bar {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(15, 23, 42, 0.98);
  color: #ffffff;
}

.mx-media-lightbox-copy {
  min-width: 0;
}

.mx-media-lightbox-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.mx-media-lightbox-download,
.mx-media-lightbox-close,
.mx-media-lightbox-nav {
  border: 0;
  color: #ffffff;
}

.mx-media-lightbox-download {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  text-decoration: none;
}

.mx-media-lightbox-download:hover {
  text-decoration: none;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.18);
}

.mx-media-lightbox-close,
.mx-media-lightbox-nav {
  position: absolute;
  width: 46px;
  height: 46px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
}

.mx-media-lightbox-close {
  top: 18px;
  right: 18px;
}

.mx-media-lightbox-nav {
  top: 50%;
  transform: translateY(-50%);
}

.mx-media-lightbox-nav.is-prev {
  left: 18px;
}

.mx-media-lightbox-nav.is-next {
  right: 18px;
}

.mx-media-lightbox-close:hover,
.mx-media-lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.2);
}

.mx-modal {
  position: fixed;
  inset: 0;
  z-index: 1400;
}

.mx-modal[hidden] {
  display: none;
}

.mx-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(4px);
}

.mx-modal-card {
  position: relative;
  width: min(560px, calc(100vw - 20px));
  max-height: min(80vh, 720px);
  margin: 40px auto 0;
  background: var(--rd-surface);
  color: var(--rd-text);
  border-radius: 6px;
  border: 1px solid var(--rd-border);
  box-shadow: 0 20px 56px rgba(15, 23, 42, 0.22);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.mx-modal-head,
.mx-modal-body {
  padding: 10px 12px;
}

.mx-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--rd-border);
}

.mx-modal-body {
  display: grid;
  gap: 10px;
  overflow: auto;
}

.mx-user-search-results {
  display: grid;
  gap: 6px;
}

.mx-user-result {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--rd-border);
  background: var(--rd-bg);
}

.mx-user-result-copy {
  min-width: 0;
}

.mx-user-result-name {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--rd-text);
  font-weight: 700;
}

.mx-user-result-meta {
  margin-top: 4px;
  color: var(--rd-muted);
  font-size: 0.84rem;
}

.mx-user-result-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 10px;
  border-radius: 6px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  font-weight: 700;
  text-decoration: none;
  max-width: 100%;
  white-space: normal;
  text-align: center;
}

.mx-user-result-action:hover {
  color: #ffffff;
  text-decoration: none;
}

@media (hover: none), (pointer: coarse) {
  .mx-message-reply-trigger {
    opacity: 1;
    transform: translateY(0);
  }

}

@media (max-width: 980px) and (min-width: 769px) {
  .mx-page {
    height: auto;
    max-height: none;
  }

  .mx-shell {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .mx-sidebar-resizer {
    display: none;
  }

  .mx-sidebar,
  .mx-main {
    max-height: none;
  }
}

/* Mobile messenger: one pane (inbox list OR thread), not stacked desktop columns */
@media (max-width: 768px) {
  .mx-page {
    max-width: none;
    margin-left: -8px;
    margin-right: -8px;
    width: calc(100% + 16px);
    padding: 0;
    height: calc(100dvh - 52px);
    min-height: 0;
  }

  .mx-shell {
    display: block;
    position: relative;
    height: 100%;
    min-height: 0;
    gap: 0;
    overflow: hidden;
  }

  .mx-sidebar-resizer {
    display: none;
  }

  .mx-sidebar-head {
    min-height: 54px;
    align-items: center;
    flex-wrap: nowrap;
  }

  .mx-sidebar-head h1 {
    font-size: 1.12rem;
  }

  .mx-sidebar-head-actions-desktop {
    display: none;
  }

  .mx-mobile-compose-wrap {
    display: block;
  }

  .mx-sidebar-icon-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  .mx-sidebar-search-overlay {
    position: absolute;
    padding: 7px 10px;
  }

  .mx-sidebar-search-overlay .mx-search-select {
    display: none;
  }

  .mx-sidebar {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .mx-folder-rail {
    padding: 6px 5px;
  }

  .mx-folder-tab {
    min-height: 56px;
    padding: 6px 3px;
    border-radius: 7px;
    font-size: 0.62rem;
  }

  .mx-folder-tab i {
    font-size: 0.92rem;
  }

  .mx-folder-create-trigger {
    min-height: 54px;
    font-size: 0.61rem;
  }

  .mx-folder-edit-trigger {
    top: 3px;
    right: 3px;
    width: 21px;
    height: 21px;
    opacity: 0.92;
    transform: none;
  }

  .mx-folder-editor.mx-modal-card-wide {
    width: 100vw;
    max-width: none;
    max-height: 100dvh;
    height: 100dvh;
    margin: 0;
    border-radius: 0;
  }

  .mx-folder-editor-toolbar {
    grid-template-columns: 1fr;
  }

  .mx-folder-editor-filters {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .mx-folder-editor-footer {
    align-items: flex-end;
  }

  .mx-sidebar,
  .mx-main {
    position: absolute;
    inset: 0;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .mx-shell.mx-shell--list-view .mx-main {
    visibility: hidden;
    pointer-events: none;
  }

  .mx-shell.mx-shell--thread-view .mx-sidebar {
    visibility: hidden;
    pointer-events: none;
  }

  .mx-sidebar-head,
  .mx-composer,
  .mx-modal-head,
  .mx-modal-body {
    padding: 10px;
  }

  .mx-thread-head {
    padding: 6px 8px;
    align-items: center;
    gap: 6px;
    flex-direction: row;
    flex-wrap: nowrap;
  }

  .mx-thread-user {
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1;
  }

  .mx-thread-user-copy {
    gap: 2px;
    min-width: 0;
  }

  .mx-thread-head .mx-avatar.lg {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    font-size: 0.85rem;
  }

  .mx-thread-head h2 {
    font-size: 1rem;
    line-height: 1.2;
  }

  .mx-thread-head p,
  .mx-thread-user-copy > p {
    display: none;
  }

  /* Для группового чата на мобиле показываем счётчик участников
     (он лежит в подзаголовке) — это и есть «N участников» вместо «Группа». */
  #mxThreadRoot[data-target-kind="group"] #mxThreadSubtitle {
    display: block;
    font-size: 0.72rem;
    line-height: 1.15;
    color: var(--rd-muted);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .mx-thread-status {
    margin-top: 0;
    font-size: 0.75rem;
    line-height: 1.2;
  }

  .mx-thread-user-copy > .mx-thread-status ~ .mx-thread-status {
    display: none;
  }

  .mx-thread-heading-row {
    gap: 6px;
  }

  .mx-thread-badge {
    padding: 2px 7px;
    font-size: 0.68rem;
  }

  .mx-thread-actions {
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
  }

  .mx-chat-mute-menu {
    position: fixed;
    top: 54px;
    right: 8px;
    width: min(248px, calc(100vw - 16px));
  }

  .mx-thread-utility-btn {
    width: 36px;
    height: 36px;
    border-radius: 6px;
  }

  .mx-conversation-list,
  .mx-sidebar-tools {
    padding-left: 6px;
    padding-right: 6px;
  }

  .mx-conversation-list {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 7px;
    padding-top: 0;
  }

  .mx-conversation-item {
    flex: 0 0 auto;
    width: 100%;
    box-sizing: border-box;
    min-height: 56px;
    padding: 10px;
  }

  .mx-main {
    overflow-x: hidden;
  }

  .mx-thread-stream {
    overflow-x: hidden;
    overflow-y: auto;
    padding: 8px 10px;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
  }

  .mx-message {
    min-width: 0;
    max-width: 100%;
  }

  .mx-message-bubble {
    width: auto;
    max-width: min(92%, 100%);
    min-width: 0;
    padding: 6px 8px;
    border-radius: 6px;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
    overflow: visible;
  }

  .mx-message-bubble:has(.mx-attachments):not(:has(.mx-message-text)) {
    padding-top: 8px;
  }

  .mx-message-reply {
    margin-bottom: 6px;
    padding: 6px 8px;
    border-radius: 6px;
  }

  .mx-message-reply-author {
    font-size: 0.7rem;
  }

  .mx-message-reply-text {
    font-size: 0.78rem;
  }

  .mx-message-text {
    font-size: 0.92rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .mx-message-text pre,
  .mx-message-text code {
    max-width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
  }

  .mx-attachments {
    margin-top: 6px;
    gap: 4px;
    width: 100%;
    min-width: 0;
  }

  .mx-attachment-tile {
    width: 100%;
    max-width: 100%;
    border-radius: 6px;
    box-sizing: border-box;
  }

  .mx-attachment-media {
    aspect-ratio: 4 / 3;
  }

  .mx-attachment-caption {
    padding: 6px 8px;
    gap: 2px;
  }

  .mx-attachment-name {
    font-size: 0.85rem;
  }

  .mx-attachment-size {
    font-size: 0.75rem;
  }

  .mx-attachment-file-card {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 6px;
    padding: 6px 8px;
    border-radius: 6px;
  }

  .mx-attachment-file-icon {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    font-size: 0.95rem;
  }

  .mx-attachment-file-name {
    font-size: 0.85rem;
  }

  .mx-attachment-file-meta {
    font-size: 0.75rem;
  }

  .mx-attachment-file-actions {
    grid-column: 1 / -1;
    flex-wrap: wrap;
    gap: 4px;
  }

  .mx-attachment-file-action {
    min-height: 32px;
    padding: 0 8px;
    font-size: 0.8rem;
  }

  .mx-message-meta {
    margin-top: 4px;
    gap: 6px;
    font-size: 0.7rem;
  }

  .mx-message-reply-trigger {
    display: none;
  }

  .mx-composer {
    padding: 8px 10px;
  }

  /* Одна строка: [скрепка] [поле ввода] [смайлы] [отправить], кнопки — иконки-квадраты.
     ВАЖНО: скоупим к .mx-composer-main, иначе ломаем .mx-send-btn в модалках. */
  .mx-composer-main {
    flex-wrap: nowrap;
    align-items: flex-end;
    gap: 6px;
  }
  .mx-composer-main #mxComposerBody {
    flex: 1 1 auto;
    order: 2;
    min-width: 0;
  }
  .mx-composer-main .mx-attach-btn {
    order: 1;
    width: 40px;
    min-height: 40px;
    padding: 0;
    flex-shrink: 0;
  }
  .mx-composer-main .mx-send-btn {
    width: 40px;
    min-height: 40px;
    padding: 0;
    margin-left: 0;
    flex-shrink: 0;
  }
  .mx-composer-main .mx-composer-submit-actions {
    order: 3;
    gap: 6px;
    flex-shrink: 0;
  }

  .mx-composer-main .mx-format-select {
    display: none !important;
  }

  .mx-context-menu {
    min-width: 190px;
    max-width: calc(100vw - 24px);
    border-radius: 12px;
    padding: 7px;
  }
  .mx-composer-main .mx-emoji-btn {
    width: 40px;
    min-height: 40px;
    padding: 0;
  }
  .mx-composer-main .mx-attach-btn-text,
  .mx-composer-main .mx-emoji-btn-text,
  .mx-composer-main .mx-send-btn-text {
    display: none;
  }
  .mx-composer-main .mx-attach-note {
    display: none;
  }

  .mx-user-result {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .mx-user-result-action {
    grid-column: 1 / -1;
  }

  .mx-thread-search-panel {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .mx-thread-search-panel .mx-search-select {
    grid-column: 1 / -1;
  }

  .mx-shell.mx-shell--thread-view .mx-mobile-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    margin-right: 2px;
    padding: 0;
    border: 1px solid var(--rd-border);
    border-radius: 6px;
    background: var(--rd-bg);
    color: var(--rd-link);
  }

  .mx-modal-card {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 24px);
  }

  .mx-attachment-browser.mx-modal-card-wide {
    width: calc(100vw - 12px);
    max-height: calc(100dvh - 12px);
    margin-top: 6px;
  }

  .mx-attachment-browser .mx-modal-head,
  .mx-attachment-browser .mx-modal-body {
    padding: 8px 10px;
  }

  .mx-attachment-browser .mx-modal-body {
    gap: 8px;
  }

  .mx-attachment-browser-list {
    max-height: 26vh;
  }

  .mx-attachment-preview {
    max-height: 30vh;
    padding: 8px;
    gap: 6px;
  }

  .mx-attachment-preview img,
  .mx-attachment-preview video {
    max-height: min(38vw, 150px);
  }

  .mx-attachment-preview-copy,
  .mx-attachment-preview-empty {
    font-size: 0.82rem;
  }

  .mx-attachment-preview-actions .mx-thread-utility-btn {
    width: 34px;
    height: 34px;
  }

  .mx-media-lightbox {
    padding: 8px;
  }

  .mx-media-lightbox-dialog {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    border-radius: 6px;
  }

  .mx-media-lightbox-stage {
    min-height: 0;
    max-height: calc(100dvh - 108px);
  }

  .mx-media-lightbox-stage img,
  .mx-media-lightbox-stage video {
    max-width: 100%;
    max-height: calc(100dvh - 120px);
    object-fit: contain;
  }

  .mx-media-lightbox-bar {
    padding: 10px 12px;
  }

  .mx-media-lightbox-nav.is-prev {
    left: 4px;
  }

  .mx-media-lightbox-nav.is-next {
    right: 4px;
  }

  .mx-media-lightbox-close {
    top: 8px;
    right: 8px;
  }
}

/* Thread actions, pins, polls and chat information. */
.mx-thread-info-trigger {
  display: block;
  max-width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.mx-thread-info-trigger:hover {
  color: var(--rd-link);
}

.mx-thread-more-wrap {
  position: relative;
  display: none;
}

.mx-thread-more-menu {
  position: absolute;
  z-index: 110;
  top: calc(100% + 7px);
  right: 0;
  width: 210px;
  padding: 7px;
  border: 1px solid var(--rd-border);
  border-radius: 8px;
  background: var(--rd-surface);
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.22);
}

.mx-thread-more-menu[hidden] {
  display: none;
}

.mx-thread-more-menu button {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--rd-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.mx-thread-more-menu button:hover {
  background: var(--rd-hover);
}

.mx-thread-more-menu i {
  width: 18px;
  color: var(--rd-link);
  text-align: center;
}

.mx-pinned-bar {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
  border: 0;
  border-bottom: 1px solid var(--rd-border);
  background: color-mix(in srgb, var(--rd-link) 7%, var(--rd-surface));
  color: var(--rd-text);
  text-align: left;
  cursor: pointer;
}

.mx-pinned-bar[hidden] {
  display: none;
}

.mx-pinned-bar > i {
  color: var(--rd-link);
  transform: rotate(-18deg);
}

.mx-pinned-bar-copy {
  min-width: 0;
  display: grid;
  gap: 1px;
  flex: 1;
}

.mx-pinned-bar-copy strong {
  font-size: 0.76rem;
}

.mx-pinned-bar-copy span {
  overflow: hidden;
  color: var(--rd-muted);
  font-size: 0.75rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.mx-pinned-bar-count {
  min-width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--rd-link);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
}

.mx-poll {
  width: min(430px, 100%);
  display: grid;
  gap: 8px;
  padding: 4px 0 2px;
}

.mx-poll-title {
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.35;
  white-space: pre-wrap;
}

.mx-poll-hint,
.mx-poll-total {
  color: inherit;
  font-size: 0.74rem;
  opacity: 0.72;
}

.mx-poll-options {
  display: grid;
  gap: 6px;
}

.mx-poll-option {
  width: 100%;
  min-height: 40px;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, currentColor 23%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, currentColor 7%, transparent);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.mx-poll-option:hover:not(:disabled),
.mx-poll-option.is-selected {
  border-color: currentColor;
  background: color-mix(in srgb, currentColor 15%, transparent);
}

.mx-poll-option:disabled {
  cursor: default;
}

.mx-poll-choice {
  opacity: 0.28;
}

.mx-poll-option.is-selected .mx-poll-choice {
  opacity: 1;
}

.mx-poll-option-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

.mx-poll-option-count {
  font-size: 0.78rem;
}

.mx-poll-create-btn {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border: 1px solid var(--rd-border);
  border-radius: 7px;
  background: var(--rd-surface);
  color: var(--rd-link);
  cursor: pointer;
}

.mx-chat-info-modal,
.mx-pins-modal {
  width: min(620px, calc(100vw - 24px));
}

.mx-chat-info-heading {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.mx-chat-info-heading > div {
  min-width: 0;
}

.mx-chat-info-heading h2,
.mx-chat-info-heading p {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.mx-chat-info-body {
  display: grid;
  gap: 16px;
}

.mx-chat-info-description {
  color: var(--rd-muted);
  line-height: 1.55;
}

.mx-chat-info-contact {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  color: var(--rd-muted);
  font-size: 0.85rem;
}

.mx-chat-info-contact span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.mx-chat-info-actions,
.mx-chat-info-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 8px;
}

.mx-chat-info-actions button,
.mx-chat-info-stats button {
  min-height: 68px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid var(--rd-border);
  border-radius: 8px;
  background: var(--rd-surface);
  color: var(--rd-text);
  cursor: pointer;
}

.mx-chat-info-actions i,
.mx-chat-info-stats i {
  color: var(--rd-link);
  font-size: 1rem;
}

.mx-chat-info-section {
  min-width: 0;
  display: grid;
  gap: 9px;
}

.mx-chat-info-section h3,
.mx-pins-section h3 {
  margin: 0;
  font-size: 0.88rem;
}

.mx-chat-info-members {
  max-height: 260px;
  display: grid;
  gap: 4px;
  overflow-y: auto;
}

.mx-chat-info-member {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 7px;
  border-radius: 7px;
  color: inherit;
  text-decoration: none;
}

.mx-chat-info-member:hover {
  background: var(--rd-hover);
}

.mx-chat-info-member > span:nth-child(2) {
  min-width: 0;
  display: grid;
}

.mx-chat-info-member strong,
.mx-chat-info-member small {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.mx-chat-info-member small,
.mx-chat-info-member em {
  color: var(--rd-muted);
  font-size: 0.72rem;
  font-style: normal;
}

.mx-chat-info-leave {
  min-height: 42px;
  border: 1px solid rgba(220, 38, 38, 0.3);
  border-radius: 7px;
  background: rgba(220, 38, 38, 0.07);
  color: #dc2626;
  cursor: pointer;
}

.mx-chat-info-owner-note {
  margin: 0;
  color: var(--rd-muted);
  font-size: 0.8rem;
}

.mx-pins-section {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.mx-pins-list {
  max-height: 230px;
  display: grid;
  gap: 6px;
  overflow-y: auto;
}

.mx-pin-row {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  padding: 9px;
  border: 1px solid var(--rd-border);
  border-radius: 7px;
  background: var(--rd-surface);
  color: var(--rd-text);
  text-align: left;
  cursor: pointer;
}

.mx-pin-row > i {
  color: var(--rd-link);
}

.mx-pin-row.is-inactive {
  opacity: 0.72;
}

.mx-pin-row > span {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.mx-pin-row strong,
.mx-pin-row small {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.mx-pin-row small {
  color: var(--rd-muted);
  font-size: 0.72rem;
}

.mx-poll-form,
.mx-poll-option-editor {
  display: grid;
  gap: 10px;
}

.mx-poll-form .mx-inline-field > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mx-poll-form [data-remove-poll-option] {
  border: 0;
  background: transparent;
  color: var(--rd-muted);
  cursor: pointer;
}

.mx-poll-multiple {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
}

.mx-inline-field textarea {
  width: 100%;
  resize: vertical;
}

@media (max-width: 768px) {
  .mx-page {
    height: calc(var(--mx-mobile-viewport-height, 100dvh) - 52px);
    min-height: 0;
  }

  .mx-main,
  .mx-shell {
    min-height: 0;
  }

  .mx-thread-actions > .mx-thread-desktop-action,
  .mx-chat-mute-wrap > .mx-thread-desktop-action {
    display: none;
  }

  .mx-chat-mute-wrap {
    display: contents;
  }

  .mx-thread-more-wrap {
    display: block;
  }

  .mx-thread-more-menu {
    position: fixed;
    top: 52px;
    right: 8px;
    width: min(230px, calc(100vw - 16px));
  }

  .mx-thread-user-copy {
    overflow: hidden;
  }

  .mx-thread-heading-row,
  .mx-thread-heading-row h2,
  .mx-thread-info-trigger {
    min-width: 0;
    max-width: 100%;
  }

  .mx-thread-info-trigger {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .mx-pinned-bar {
    min-height: 42px;
    padding: 5px 10px;
  }

  .mx-chat-info-modal,
  .mx-pins-modal,
  .mx-poll-modal {
    width: calc(100vw - 12px);
    max-height: calc(var(--mx-mobile-viewport-height, 100dvh) - 12px);
  }

  .mx-chat-info-actions,
  .mx-chat-info-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mx-chat-info-actions button,
  .mx-chat-info-stats button {
    min-height: 62px;
    padding: 5px;
    font-size: 0.72rem;
  }

  .mx-poll-create-btn {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
  }
}

@media (max-width: 480px) {
  .mx-page {
    height: calc(var(--mx-mobile-viewport-height, 100dvh) - 48px);
  }
}

/* Composer tools, contacts and strict mobile visual viewport containment. */
.mx-composer-tools {
  position: relative;
  order: 1;
  flex: 0 0 auto;
}

.mx-composer-tools .mx-attach-btn {
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
}

.mx-composer-tools-menu {
  position: absolute;
  z-index: 130;
  left: 0;
  bottom: calc(100% + 8px);
  width: 210px;
  padding: 7px;
  border: 1px solid var(--rd-border);
  border-radius: 8px;
  background: var(--rd-surface);
  box-shadow: 0 16px 38px rgba(15, 23, 42, 0.22);
}

.mx-composer-tools-menu[hidden] {
  display: none;
}

.mx-composer-tools-menu button {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  color: var(--rd-text);
  text-align: left;
  cursor: pointer;
}

.mx-composer-tools-menu button:hover,
.mx-composer-tools-menu button:focus-visible {
  background: var(--rd-hover);
  color: var(--rd-link);
}

.mx-composer-tools-menu button i {
  width: 18px;
  color: var(--rd-link);
  text-align: center;
}

.mx-contacts-trigger-mobile {
  display: none;
}

.mx-contacts-trigger-desktop {
  min-height: 38px;
  white-space: nowrap;
}

@media (min-width: 769px) {
  .mx-sidebar-head {
    align-content: flex-start;
    padding-bottom: 11px;
  }

  .mx-folder-rail {
    padding-top: 54px;
  }

  .mx-sidebar-head-actions {
    width: 100%;
    flex: 1 1 100%;
    justify-content: flex-start;
  }
}

.mx-contacts-modal {
  width: min(920px, calc(100vw - 28px));
}

.mx-contacts-layout {
  min-height: 480px;
  max-height: min(72vh, 680px);
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(340px, 1.1fr);
  overflow: hidden;
}

.mx-contacts-list-pane {
  min-width: 0;
  min-height: 0;
  padding: 12px;
  border-right: 1px solid var(--rd-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mx-contacts-status,
.mx-contact-info-placeholder {
  min-height: 180px;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--rd-muted);
  text-align: center;
}

.mx-contact-info-placeholder {
  flex-direction: column;
}

.mx-contact-info-placeholder i {
  font-size: 2rem;
}

.mx-contacts-list {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 6px;
  overscroll-behavior: contain;
}

.mx-contact-row {
  min-width: 0;
  padding: 7px;
  border: 1px solid transparent;
  border-radius: 8px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  background: var(--rd-bg);
}

.mx-contact-row:hover {
  border-color: var(--rd-border);
  background: var(--rd-hover);
}

.mx-contact-row-avatar,
.mx-contact-avatar {
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--rd-hover);
  color: var(--rd-link);
  font-weight: 750;
  text-decoration: none;
}

.mx-contact-row-avatar {
  width: 44px;
  height: 44px;
}

.mx-contact-avatar {
  width: 72px;
  height: 72px;
  flex: 0 0 72px;
  font-size: 1.15rem;
}

.mx-contact-row-avatar img,
.mx-contact-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mx-contact-row-name {
  min-width: 0;
  padding: 3px 0;
  border: 0;
  display: grid;
  gap: 3px;
  background: transparent;
  color: var(--rd-text);
  text-align: left;
  cursor: pointer;
}

.mx-contact-row-name strong,
.mx-contact-row-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mx-contact-row-name span {
  color: var(--rd-muted);
  font-size: 0.76rem;
}

.mx-contact-row-write {
  min-width: 92px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--rd-border);
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--rd-surface);
  color: var(--rd-link);
  text-decoration: none;
}

.mx-contact-row-write.is-disabled,
.mx-contact-write.is-disabled {
  opacity: 0.42;
  color: var(--rd-muted);
  cursor: not-allowed;
}

.mx-contact-info-pane {
  min-width: 0;
  min-height: 0;
  padding: 18px;
  overflow-y: auto;
}

.mx-contact-info-back {
  display: none;
}

.mx-contact-info-heading {
  display: flex;
  align-items: center;
  gap: 14px;
}

.mx-contact-info-heading h3,
.mx-contact-info-heading p {
  margin: 0;
}

.mx-contact-info-heading p {
  margin-top: 4px;
  color: var(--rd-muted);
}

.mx-contact-info-fields,
.mx-chat-info-profile-fields {
  margin-top: 18px;
  display: grid;
  gap: 8px;
}

.mx-contact-info-field,
.mx-chat-info-profile-fields > div {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--rd-border);
  border-radius: 7px;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: start;
  gap: 9px;
}

.mx-contact-info-field > i,
.mx-chat-info-profile-fields > div > i {
  margin-top: 3px;
  color: var(--rd-link);
  text-align: center;
}

.mx-contact-info-field > span,
.mx-chat-info-profile-fields > div > span {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.mx-contact-info-field small,
.mx-chat-info-profile-fields small {
  color: var(--rd-muted);
  font-size: 0.7rem;
}

.mx-contact-info-field strong,
.mx-chat-info-profile-fields strong {
  overflow-wrap: anywhere;
  font-size: 0.86rem;
}

.mx-contact-info-about {
  margin: 16px 0 0;
  padding: 12px;
  border-radius: 7px;
  background: var(--rd-hover);
  color: var(--rd-muted);
  line-height: 1.55;
  white-space: pre-wrap;
}

.mx-contact-info-actions {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mx-contact-info-actions a,
.mx-contact-info-actions button {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--rd-border);
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--rd-surface);
  color: var(--rd-link);
  text-decoration: none;
}

@media (max-width: 768px) {
  html.mx-mobile-messenger-active,
  html.mx-mobile-messenger-active body.mx-body {
    width: 100%;
    height: var(--mx-mobile-viewport-height, 100dvh);
    min-height: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .mx-page {
    position: fixed;
    top: var(--mx-mobile-page-top, 52px);
    right: 0;
    bottom: auto;
    left: 0;
    width: 100%;
    height: var(--mx-mobile-page-height, calc(100dvh - 52px));
    margin: 0;
    padding: 0;
    overflow: hidden;
  }

  .mx-main,
  .mx-thread-stream,
  .mx-sidebar,
  .mx-conversation-list {
    min-height: 0;
  }

  .mx-composer {
    flex: 0 0 auto;
    max-height: min(190px, 42vh);
  }

  .mx-composer-main .mx-emoji-picker {
    display: none !important;
  }

  .mx-composer-main .mx-composer-tools {
    order: 1;
  }

  .mx-composer-tools-menu {
    position: fixed;
    right: auto;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 58px);
    left: 8px;
    width: min(230px, calc(100vw - 16px));
  }

  .mx-contacts-trigger-desktop {
    display: none;
  }

  .mx-contacts-trigger-mobile {
    display: inline-flex;
    order: 3;
  }

  .mx-sidebar-head-actions #mxConversationSearchButton {
    order: 1;
  }

  .mx-mobile-compose-wrap {
    order: 2;
  }

  .mx-contacts-modal {
    width: calc(100vw - 12px);
    max-height: calc(var(--mx-mobile-viewport-height, 100dvh) - 12px);
  }

  .mx-contacts-layout {
    height: calc(var(--mx-mobile-viewport-height, 100dvh) - 82px);
    min-height: 0;
    max-height: calc(var(--mx-mobile-viewport-height, 100dvh) - 82px);
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .mx-contacts-list-pane {
    border-right: 0;
  }

  .mx-contact-info-placeholder {
    display: none;
  }

  .mx-contact-info-pane {
    display: none;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    padding: 12px;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  #mxContactsModal.is-contact-info-open .mx-contacts-list-pane {
    display: none;
  }

  #mxContactsModal.is-contact-info-open .mx-contact-info-pane {
    display: block;
  }

  .mx-contact-info-back {
    min-height: 36px;
    margin: 0 0 12px;
    padding: 0 8px;
    border: 0;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: transparent;
    color: var(--rd-link);
  }

  .mx-contact-row-write {
    width: 40px;
    min-width: 40px;
    padding: 0;
  }

  .mx-contact-row-write span {
    display: none;
  }
}

@media (max-width: 480px) {
  .mx-page {
    top: var(--mx-mobile-page-top, 0px);
    height: var(--mx-mobile-page-height, 100dvh);
  }
}

@media (max-width: 480px) {
  .mx-page {
    height: var(--mx-mobile-page-height, 100dvh);
  }
}



.mx-sidebar-head-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: nowrap;
}

.mx-filter-strip {
  padding: 0 6px 6px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mx-filter-chip {
  border: 1px solid var(--rd-border);
  background: var(--rd-bg);
  color: var(--rd-text);
  border-radius: 6px;
  padding: 6px 10px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.84rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  white-space: nowrap;
}

.mx-filter-chip.is-active {
  background: var(--rd-accent);
  border-color: var(--rd-accent);
  color: #fff;
}

.mx-folder-rail {
  padding: 0 8px 8px;
  display: grid;
  gap: 8px;
}

.mx-folder-group {
  background: var(--rd-bg);
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  padding: 8px;
}

.mx-folder-group-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--rd-muted);
  margin-bottom: 6px;
}

.mx-folder-list {
  display: grid;
  gap: 6px;
}

.mx-folder-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--rd-text);
  text-decoration: none;
}

.mx-folder-link.is-active,
.mx-folder-link:hover {
  background: var(--rd-hover);
  color: var(--rd-text);
}

.mx-folder-link.is-disabled {
  opacity: 0.65;
  cursor: default;
  pointer-events: none;
}

.mx-folder-note {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--rd-muted);
}

.mx-folder-empty,
.mx-conversation-meta {
  color: var(--rd-muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mx-row-badge,
.mx-thread-badge,
.mx-member-role,
.mx-management-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--rd-hover);
  color: var(--rd-link);
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 700;
}

.mx-thread-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--rd-border);
}

.mx-thread-heading-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mx-thread-actions {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.mx-chat-mute-wrap {
  position: relative;
}

.mx-thread-utility-btn.is-muted {
  border-color: rgba(100, 116, 139, 0.42);
  background: rgba(148, 163, 184, 0.14);
  color: #64748b;
}

.mx-chat-mute-menu {
  position: absolute;
  z-index: 95;
  top: calc(100% + 7px);
  right: 0;
  width: 248px;
  padding: 7px;
  border: 1px solid var(--rd-border);
  border-radius: 8px;
  display: grid;
  gap: 3px;
  background: var(--rd-surface);
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.22);
}

.mx-chat-mute-menu[hidden] {
  display: none;
}

.mx-chat-mute-title {
  padding: 5px 8px 7px;
  color: var(--rd-muted);
  font-size: 0.74rem;
  line-height: 1.3;
}

.mx-chat-mute-menu button {
  min-height: 36px;
  padding: 0 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--rd-text);
  text-align: left;
  cursor: pointer;
}

.mx-chat-mute-menu button:hover,
.mx-chat-mute-menu button:focus-visible {
  background: var(--rd-hover);
  outline: none;
}

.mx-chat-mute-menu .mx-chat-unmute-action {
  margin-top: 4px;
  border-top: 1px solid var(--rd-border);
  border-radius: 0 0 6px 6px;
  color: var(--rd-link);
}

.mx-folder-bind-panel {
  display: grid;
  gap: 6px;
}

.mx-folder-bind-list {
  display: grid;
  gap: 6px;
}

.mx-folder-bind-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--rd-bg);
}

.mx-folder-bind-copy,
.mx-folder-bind-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.mx-folder-bind-state {
  font-size: 0.8rem;
  color: var(--rd-link);
}

.mx-folder-bind-state.is-muted {
  color: var(--rd-muted);
}

.mx-folder-bind-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.mx-folder-bind-controls select,
.mx-inline-field input,
.mx-inline-field select {
  min-height: 36px;
  border-radius: 6px;
  border: 1px solid var(--rd-border);
  background: var(--rd-bg);
  color: var(--rd-text);
  padding: 0 10px;
}

.mx-send-btn-secondary {
  background: var(--rd-bg);
  color: var(--rd-link);
  border: 1px solid var(--rd-border);
}

.mx-send-btn-secondary.is-danger {
  color: #b91c1c;
}

.mx-group-action-stack {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mx-invite-panel {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  background: var(--rd-surface);
}

.mx-invite-panel[hidden] {
  display: none;
}

.mx-invite-panel-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mx-invite-panel-actions .mx-send-btn {
  text-decoration: none;
}

.mx-management-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 10px 14px 0;
}

.mx-management-pane {
  background: var(--rd-bg);
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  padding: 10px;
}

.mx-management-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.mx-management-head h3 {
  margin: 0;
}

.mx-management-hint {
  margin: -4px 0 12px;
  color: var(--rd-muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

.mx-member-list,
.mx-request-list,
.mx-attachment-browser-list {
  display: grid;
  gap: 8px;
}

.mx-attachment-browser-list {
  max-height: 52vh;
  overflow: auto;
  padding-right: 2px;
}

.mx-member-row,
.mx-request-row,
.mx-attachment-browser-item,
.mx-user-result {
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  background: var(--rd-surface);
}

.mx-member-row,
.mx-request-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  align-items: center;
}

.mx-member-copy,
.mx-request-copy {
  display: grid;
  gap: 4px;
}

.mx-member-controls,
.mx-request-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.mx-modal-card-wide {
  width: min(780px, calc(100vw - 16px));
}

.mx-start-chat-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}


.mx-attachment-browser-controls {
  display: grid;
  grid-template-columns: minmax(0, 2fr) repeat(2, minmax(170px, 1fr));
  gap: 8px;
  align-items: end;
}

.mx-attachment-browser-search {
  min-width: 0;
}

.mx-attachment-browser-field {
  min-width: 0;
}

.mx-attachment-browser-field select,
.mx-attachment-browser-field input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  background: var(--rd-bg);
  color: var(--rd-text);
  padding: 8px 10px;
}

.mx-attachment-preview-meta {
  color: var(--rd-muted);
  font-size: 0.82rem;
}

.mx-inline-form {
  display: grid;
  gap: 10px;
}

.mx-inline-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mx-inline-field {
  display: grid;
  gap: 6px;
}

.mx-attachment-browser-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.02fr) minmax(260px, 0.98fr);
  gap: 10px;
}

.mx-attachment-browser-main,
.mx-attachment-preview {
  display: grid;
  gap: 10px;
  min-height: 0;
}

.mx-attachment-browser-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--rd-text);
  font: inherit;
  text-align: left;
}

.mx-attachment-browser-item.is-active {
  border-color: var(--rd-accent);
}

.mx-attachment-browser-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.mx-attachment-browser-copy strong,
.mx-attachment-preview-copy strong {
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--rd-text);
}

.mx-attachment-preview {
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  background: var(--rd-bg);
  padding: 10px;
  align-content: start;
  max-height: 48vh;
  overflow: auto;
}

.mx-attachment-preview img,
.mx-attachment-preview video {
  width: 100%;
  border-radius: 6px;
  max-height: 280px;
  object-fit: contain;
  background: #000;
}

.mx-attachment-preview-empty {
  color: var(--rd-muted);
  font-size: 0.9rem;
}

.mx-attachment-preview-copy {
  color: var(--rd-text);
  font-size: 0.9rem;
}

.mx-attachment-preview-copy > div:not(.mx-attachment-preview-meta) {
  color: var(--rd-text);
}

.mx-attachment-browser .mx-inline-field > span {
  color: var(--rd-muted);
}

.mx-attachment-browser .mx-empty {
  color: var(--rd-muted);
}

.mx-attachment-preview-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.mx-attachment-preview-actions[hidden] {
  display: none;
}

@media (max-width: 1320px) {
  .mx-attachment-browser-controls {
    grid-template-columns: minmax(0, 1.5fr) repeat(2, minmax(0, 1fr));
  }

  .mx-attachment-browser-search {
    grid-column: auto;
  }
}

@media (max-width: 1080px) {
  .mx-management-grid,
  .mx-attachment-browser-layout {
    grid-template-columns: 1fr;
  }

  .mx-attachment-browser-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1080px) and (min-width: 981px) {
  .mx-shell {
    --mx-sidebar-width: 400px;
    grid-template-columns: minmax(380px, var(--mx-sidebar-width)) 8px minmax(0, 1fr);
  }
}

@media (max-width: 720px) {
  .mx-member-row,
  .mx-request-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .mx-inline-grid,
  .mx-folder-bind-controls,
  .mx-group-action-stack,
  .mx-attachment-browser-controls {
    grid-template-columns: 1fr;
  }
}

.mx-filter-strip-secondary {
  padding-top: 0;
}

.mx-filter-chip-system {
  background: var(--rd-surface);
}

.mx-folder-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.mx-folder-scroll .mx-folder-link {
  flex: 0 0 auto;
  white-space: nowrap;
  border: 1px solid var(--rd-border);
  background: var(--rd-surface);
}

.mx-thread-utility-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  background: var(--rd-bg);
  color: var(--rd-link);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mx-group-settings-modal.mx-modal-card-wide {
  width: min(900px, calc(100vw - 16px));
}

.mx-group-settings-layout {
  display: grid;
  gap: 10px;
}

.mx-group-settings-layout .mx-management-pane {
  background: var(--rd-bg);
}

.mx-group-settings-modal .mx-inline-form .mx-send-btn {
  justify-self: start;
}

.mx-input-file-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.mx-group-avatar-picker {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--rd-border);
  border-radius: 6px;
  background: var(--rd-surface);
}

.mx-group-avatar-preview {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mx-group-avatar-controls {
  min-width: 0;
  display: grid;
  gap: 8px;
  justify-items: start;
}

.mx-group-avatar-trigger {
  cursor: pointer;
}

.mx-group-avatar-note {
  min-width: 0;
  max-width: 100%;
  color: var(--rd-muted);
  font-size: 0.82rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mx-attachment-browser.mx-modal-card-wide {
  width: min(1320px, calc(100vw - 24px));
}

html[data-theme="dark"] .mx-attachment-preview,
html.dark .mx-attachment-preview {
  background: var(--rd-surface);
  color: var(--rd-text);
}

html[data-theme="dark"] .mx-attachment-browser-item,
html.dark .mx-attachment-browser-item {
  color: var(--rd-text);
}

html[data-theme="dark"] .mx-attachment-preview-copy,
html[data-theme="dark"] .mx-attachment-preview-copy strong,
html[data-theme="dark"] .mx-attachment-preview-copy > div:not(.mx-attachment-preview-meta),
html.dark .mx-attachment-preview-copy,
html.dark .mx-attachment-preview-copy strong,
html.dark .mx-attachment-preview-copy > div:not(.mx-attachment-preview-meta) {
  color: var(--rd-text);
}

/* ── Пересылка сообщений (2026-06-10) ───────────────────────────── */

.mx-forward-preview {
  margin-bottom: 12px;
  padding: 8px 12px;
  border-left: 3px solid var(--rd-accent, #2563eb);
  background: var(--rd-row-alt, #f1f5f9);
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--rd-muted, #64748b);
  max-height: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mx-forward-preview:empty {
  display: none;
}

.mx-forward-list {
  margin-top: 12px;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mx-forward-target {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--rd-text, #0f172a);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}

.mx-forward-target:hover {
  background: var(--rd-hover, #f0f4ff);
}

.mx-forward-target:disabled {
  opacity: 0.6;
  cursor: wait;
}

.mx-forward-target i {
  width: 18px;
  text-align: center;
  color: var(--rd-muted, #64748b);
  font-size: 12px;
  flex-shrink: 0;
}

.mx-forward-target span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Множественный выбор сообщений для пересылки (2026-06-15) ────── */

/* В режиме выбора курсор-указатель по всему потоку, реплай-триггеры прячем */
.mx-selecting .mx-thread-stream { cursor: pointer; }
.mx-selecting .mx-message-reply-trigger { display: none !important; }

/* Подсветка выбранного сообщения */
.mx-message.is-selected .mx-message-bubble {
  outline: 2px solid var(--rd-accent, #2563eb);
  outline-offset: 2px;
  background: var(--rd-hover, rgba(37, 99, 235, 0.08));
}

.mx-message.is-selected::after {
  content: "\f00c";
  /* \f00c = check; перечисляем версии — бандл all.min.css может быть FA5/6/7 */
  font-family: "Font Awesome 7 Free", "Font Awesome 6 Free", "Font Awesome 5 Free";
  font-weight: 900;
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--rd-accent, #2563eb);
  color: #fff;
  z-index: 2;
}

.mx-message { position: relative; }

/* Нижняя панель режима выбора (заменяет композер сверху) */
.mx-selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--rd-border, #e2e8f0);
  background: var(--rd-surface, #fff);
  flex-wrap: wrap;
}

.mx-selection-count-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--rd-text, #0f172a);
}

.mx-selection-count-wrap i {
  color: var(--rd-accent, #2563eb);
}

.mx-selection-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.mx-selection-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s ease, color 0.12s ease;
}

.mx-selection-btn--ghost {
  background: transparent;
  border-color: var(--rd-border, #cbd5e1);
  color: var(--rd-muted, #64748b);
}

.mx-selection-btn--ghost:hover {
  background: var(--rd-hover, #f0f4ff);
  color: var(--rd-text, #0f172a);
}

.mx-selection-btn--primary {
  background: var(--rd-accent, #2563eb);
  border-color: var(--rd-accent, #2563eb);
  color: #fff;
}

.mx-selection-btn--primary:hover {
  background: var(--rd-link, #1d4ed8);
}

.mx-selection-btn--primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Mobile: folders live above the chat list and scroll horizontally. */
@media (max-width: 768px) {
  .mx-sidebar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .mx-sidebar-content {
    display: contents;
  }

  .mx-sidebar-head {
    grid-column: 1;
    grid-row: 1;
  }

  .mx-folder-rail {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    min-width: 0;
    min-height: 61px;
    padding: 6px 7px;
    border-top: 1px solid var(--rd-border);
    border-bottom: 1px solid var(--rd-border);
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 6px;
    overflow: hidden;
  }

  .mx-folder-rail-scroll {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex: 1 1 auto;
    flex-direction: row;
    align-items: stretch;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 0 3px;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    overscroll-behavior-x: contain;
  }

  .mx-folder-rail-section {
    display: flex;
    flex: 0 0 auto;
    flex-direction: row;
    gap: 6px;
  }

  .mx-folder-rail-divider {
    width: 1px;
    min-width: 1px;
    height: 36px;
    margin: 6px 1px;
  }

  .mx-folder-tab,
  .mx-folder-tab-wrap {
    width: 108px;
    min-width: 108px;
    min-height: 46px;
    height: 46px;
    flex: 0 0 108px;
    scroll-snap-align: start;
  }

  .mx-folder-tab {
    padding: 7px 9px;
    border-radius: 7px;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 7px;
    font-size: 0.7rem;
    text-align: left;
  }

  .mx-folder-tab i {
    flex: 0 0 auto;
    font-size: 0.9rem;
  }

  .mx-folder-tab span {
    min-width: 0;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    -webkit-line-clamp: unset;
  }

  .mx-folder-tab-wrap .mx-folder-tab {
    padding-right: 29px;
  }

  .mx-folder-create-trigger {
    width: 64px;
    min-width: 64px;
    min-height: 49px;
    height: 49px;
    margin: 0;
    padding: 5px 3px;
    flex: 0 0 64px;
    border-radius: 7px;
    font-size: 0.58rem;
  }

  .mx-folder-edit-trigger {
    top: 12px;
    right: 5px;
    width: 22px;
    height: 22px;
  }

  .mx-conversation-list {
    grid-column: 1;
    grid-row: 3;
    min-width: 0;
    min-height: 0;
    padding-top: 6px;
  }
}

/* Keep viewport recovery overrides last: older mobile rules above use static 100dvh. */
@media (min-width: 769px) {
  .mx-folder-rail {
    padding-top: 54px;
  }
}

@media (max-width: 768px) {
  body.authenticated.mx-body {
    padding-top: 0;
  }

  body.mx-body .nx-navbar {
    display: none !important;
  }

  body.mx-body .mx-page {
    top: var(--mx-mobile-page-top, 0px);
    height: var(--mx-mobile-page-height, 100dvh);
    min-height: 0;
  }

  body.mx-body .nx-mobile-drawer {
    top: 0;
  }

  body.mx-body .nx-mobile-backdrop {
    inset: 0;
  }

  body.mx-body .mx-sidebar-head-actions > .nx-notification-dd {
    position: relative;
    order: 4;
    flex: 0 0 40px;
  }

  body.mx-body .mx-sidebar-head-actions > .nx-notification-dd::after {
    display: none;
  }

  body.mx-body .mx-sidebar-head-actions > .nx-notification-dd .nx-bell,
  body.mx-body .mx-sidebar-head-actions > .nx-burger {
    width: 40px;
    height: 40px;
    min-width: 40px;
    padding: 0;
    border: 1px solid var(--rd-border);
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--rd-bg);
    color: var(--rd-text);
    box-shadow: none;
  }

  body.mx-body .mx-sidebar-head-actions > .nx-notification-dd .nx-bell:hover,
  body.mx-body .mx-sidebar-head-actions > .nx-burger:hover,
  body.mx-body.nx-mobile-nav-open .mx-sidebar-head-actions > .nx-burger {
    border-color: color-mix(in srgb, var(--rd-accent) 42%, var(--rd-border));
    background: var(--rd-hover);
    color: var(--rd-accent);
  }

  body.mx-body .mx-sidebar-head-actions > .nx-notification-dd .nx-notification-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    left: auto !important;
    width: min(300px, calc(100vw - 16px));
    min-width: 0;
    max-width: calc(100vw - 16px);
    max-height: min(62vh, 440px);
  }

  body.mx-body .mx-sidebar-head-actions > .nx-burger {
    order: 5;
    flex: 0 0 40px;
  }

  .mx-thread-actions > .mx-thread-desktop-action,
  .mx-chat-mute-wrap > .mx-thread-desktop-action {
    display: none;
  }

  .mx-thread-more-wrap {
    display: block;
  }
}

@media (max-width: 480px) {
  body.mx-body .mx-page {
    height: var(--mx-mobile-page-height, 100dvh);
  }
}

@media (max-width: 360px) {
  body.mx-body .mx-sidebar-head-copy {
    display: none;
  }

  body.mx-body .mx-sidebar-head-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

/*
 * The desktop chat column is user-resizable. Switch its actions to the same
 * compact controls as mobile when the column itself (not the viewport) can no
 * longer fit every labelled button.
 */
@media (min-width: 769px) {
  .mx-sidebar-content {
    container-name: mx-sidebar-content;
    container-type: inline-size;
  }

  @container mx-sidebar-content (max-width: 356px) {
    .mx-sidebar-head-actions {
      gap: 6px;
    }

    .mx-sidebar-head-actions-desktop,
    .mx-contacts-trigger-desktop {
      display: none;
    }

    .mx-mobile-compose-wrap {
      display: block;
      order: 2;
    }

    .mx-contacts-trigger-mobile {
      display: inline-flex;
      order: 3;
    }

    .mx-sidebar-head-actions #mxConversationSearchButton {
      order: 1;
    }
  }

  @container mx-sidebar-content (min-width: 357px) and (max-width: 386px) {
    .mx-sidebar-head-actions,
    .mx-sidebar-head-actions-desktop {
      gap: 4px;
    }

    .mx-sidebar-head-actions .mx-new-dialog-btn {
      padding-inline: 8px;
    }
  }
}
