/* =========================================================
   4HE / PRIVATE MESSAGES
   Dialog list, new message and chat
   ========================================================= */

/* =========================
   PAGE
   ========================= */

.pm-page {
  display: grid;
  gap: 14px;
  margin: 0 0 16px;
}

.pm-card,
.pm-chat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: none;
  overflow: hidden;
}

/* =========================
   TOP BAR
   ========================= */

.pm-card--hero-compact {
  padding: 14px 16px;
}

.pm-card__hero-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
}

.pm-card__hero-left {
  min-width: 0;
}

.pm-card__hero-left--with-back,
.pm-card__hero-left--dialog {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pm-card__hero-title {
  margin: 0;
  color: var(--text);
  font-size: 24px;
  line-height: 1.12;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.pm-toolbar__nav--iconbar,
.pm-card__hero-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.pm-toolbar__icon-btn,
.pm-card__hero-back,
.pm-card__hero-action {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--text-soft);
  text-decoration: none;
  cursor: pointer;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease,
    transform 0.18s ease;
}

.pm-toolbar__icon-btn:hover,
.pm-card__hero-back:hover,
.pm-card__hero-action:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
  color: var(--text);
  text-decoration: none;
}

.pm-toolbar__icon-btn:active,
.pm-card__hero-back:active,
.pm-card__hero-action:active {
  transform: scale(0.97);
}

.pm-toolbar__icon-btn .i-svg,
.pm-card__hero-back .i-svg,
.pm-card__hero-action .i-svg {
  width: 17px;
  height: 17px;
}

.pm-card__hero-action--ignore:hover {
  color: var(--accent-main);
}

.pm-card__hero-action--delete:hover {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}

/* =========================
   DIALOG HEADER USER
   ========================= */

.pm-card__hero-user {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.pm-card__hero-user-avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-soft);
  overflow: hidden;
}

.pm-card__hero-user-avatar .i-svg {
  width: 17px;
  height: 17px;
}

.pm-card__hero-user-avatar.has-image {
  color: transparent;
}

.pm-card__hero-user-name,
.pm-card__hero-user-name a {
  min-width: 0;
  display: block;
  color: var(--text);
  font-size: 15px;
  line-height: 1.25;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pm-card__hero-user-name a:hover {
  color: var(--accent-main);
  text-decoration: none;
}

/* =========================
   DIALOGS LIST
   ========================= */

.pm-card--dialogs {
  padding: 10px;
}

.pm-dialogs-shell {
  min-width: 0;
}

/* DLE native PM table reset */

#pmlist {
  display: block;
}

#pmlist table.pm {
  width: 100% !important;
  border-collapse: collapse !important;
  border-spacing: 0 !important;
  background: transparent !important;
}

#pmlist table.pm thead,
#pmlist td.pm_checkbox,
#pmlist td.pm_dialog_check,
#pmlist table.pm_navigation {
  display: none !important;
}

#pmlist table.pm tbody {
  display: grid !important;
  gap: 8px;
}

#pmlist table.pm tbody tr {
  min-height: 70px;
  display: grid !important;
  grid-template-columns: 46px minmax(0, 1fr) !important;
  align-items: center;
  gap: 12px;
  margin: 0 !important;
  padding: 9px 12px !important;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
  transition:
    background 0.18s ease,
    border-color 0.18s ease;
}

#pmlist table.pm tbody tr:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

#pmlist table.pm td {
  padding: 0 !important;
  margin: 0 !important;
  background: transparent !important;
  border: 0 !important;
  vertical-align: middle;
}

#pmlist td.pm_dialog_avatar {
  display: flex;
  align-items: center;
  justify-content: center;
}

#pmlist td.pm_dialog_main {
  min-width: 0;
  width: 100%;
  display: flex;
  align-items: center;
}

/* Custom dialog markup */

.pm-dialog {
  width: 100%;
  min-width: 0;
  display: block;
  color: inherit;
  text-decoration: none;
}

.pm-dialog:hover {
  color: inherit;
  text-decoration: none;
}

.pm-dialog__avatar {
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-main-soft);
  border: 1px solid rgba(45, 123, 255, 0.12);
  border-radius: 50%;
  color: var(--accent-main);
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
}

.pm-dialog__avatar--system {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-soft);
}

.pm-dialog__avatar .i-svg {
  width: 17px;
  height: 17px;
}

.pm-dialog__top {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  column-gap: 10px;
}

.pm-dialog__name {
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.25;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pm-dialog__time {
  justify-self: end;
  color: var(--text-fade);
  font-size: 11px;
  line-height: 1.25;
  white-space: nowrap;
  text-align: right;
}

.pm-dialog__preview {
  min-width: 0;
  margin-top: 4px;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pm-dialog__author {
  color: var(--text-soft);
  font-weight: 600;
}

.pm-dialog__colon {
  margin-right: 4px;
}

/* =========================
   NEW MESSAGE
   ========================= */

.pm-card--compose {
  padding-bottom: 20px;
}

.pm-section-head {
  padding: 20px 22px 0;
  display: grid;
  gap: 8px;
}

.pm-section-head__title {
  margin: 0;
  color: var(--text);
  font-size: 22px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.pm-section-head__text {
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.6;
}

.pm-compose {
  padding: 18px 22px 0;
  display: grid;
  gap: 16px;
}

.pm-compose__top {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.pm-compose__group {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.pm-compose__label {
  color: var(--text);
  font-size: 13px;
  line-height: 1.3;
  font-weight: 600;
}

.pm-compose__input {
  width: 100%;
  min-height: 50px;
  padding: 0 15px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 15px;
  color: var(--text);
  outline: 0;
  box-shadow: none;
  font-size: 14px;
  line-height: 1;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.pm-compose__input::placeholder {
  color: var(--text-fade);
  opacity: 1;
}

.pm-compose__input:hover {
  background: var(--surface);
  border-color: var(--border-strong);
}

.pm-compose__input:focus {
  background: var(--surface);
  border-color: rgba(45, 123, 255, 0.34);
  box-shadow: 0 0 0 3px rgba(45, 123, 255, 0.08);
}

.pm-compose__editor {
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 18px;
}

.pm-compose__editor textarea,
.pm-compose__editor .wseditor,
.pm-compose__editor .bb-editor textarea {
  min-height: 180px !important;
  background: var(--surface) !important;
  border-radius: 15px !important;
}

.pm-compose__editor .bbcodes,
.pm-compose__editor .editor-panel,
.pm-compose__editor .bb-pane {
  margin: 0;
  padding: 0 0 10px;
  background: transparent;
  border: 0;
}

.pm-compose__recaptcha {
  min-width: 0;
}

.pm-compose__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.pm-compose__captcha {
  min-width: min(100%, 320px);
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.pm-compose__captcha-image {
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 13px;
  overflow: hidden;
}

.pm-compose__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pm-compose__btn {
  min-height: 44px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-radius: 14px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  font-size: 14px;
  line-height: 1;
  font-weight: 700;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease,
    transform 0.18s ease;
}

.pm-compose__btn:active {
  transform: scale(0.985);
}

.pm-compose__btn--primary {
  background: var(--accent-main);
  color: #fff;
}

.pm-compose__btn--primary:hover {
  background: var(--accent-main-hover);
  color: #fff;
}

.pm-compose__btn--ghost {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.pm-compose__btn--ghost:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
  color: var(--text);
}

.pm-compose__btn .i-svg {
  width: 16px;
  height: 16px;
}

/* =========================
   CHAT
   ========================= */

.pm-chat {
  overflow: visible;
}

.pm-chat__body {
  min-height: 320px;
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 18px 20px;
  background: var(--surface);
  overflow: visible;
}

.pm-chat__message-wrap {
  min-width: 0;
  scroll-margin-top: calc(var(--header-h) + 16px);
}

.pm-chat__message-wrap.is-referenced .pm-message__bubble {
  border-color: rgba(45, 123, 255, 0.34);
  box-shadow: 0 0 0 3px rgba(45, 123, 255, 0.08);
}

/* =========================
   MESSAGE
   ========================= */

.pm-message {
  position: relative;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: end;
}

.pm-message__avatar {
  position: relative;
  width: 38px;
  height: 38px;
  align-self: end;
}

.pm-message__avatar-cover {
  width: 38px;
  height: 38px;
  display: block;
  background-color: var(--surface-2);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  border-radius: 50%;
  color: transparent;
  font-size: 0;
  overflow: hidden;
}

.pm-message__online {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 12px;
  height: 12px;
  background: var(--success);
  border: 2px solid var(--surface);
  border-radius: 50%;
}

.pm-message__content {
  position: relative;
  min-width: 0;
  max-width: min(100%, 560px);
}

.pm-message__bubble {
  position: relative;
  min-width: 0;
  padding: 12px 14px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 17px;
  border-top-left-radius: 9px;
}

.pm-message__author {
  margin: 0 0 5px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.25;
  font-weight: 700;
}

.pm-message__text {
  color: var(--text);
  font-size: 14px;
  line-height: 1.68;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.pm-message__text p {
  margin: 0 0 0.75em;
}

.pm-message__text p:last-child {
  margin-bottom: 0;
}

.pm-message__text a {
  color: var(--accent-main);
  text-decoration: none;
}

.pm-message__text a:hover {
  color: var(--accent-main-hover);
  text-decoration: underline;
}

.pm-message__text img {
  max-width: 100%;
  height: auto;
  border-radius: 14px;
}

.pm-message__date-inside {
  margin-top: 8px;
  color: var(--text-fade);
  font-size: 11px;
  line-height: 1.25;
  text-align: right;
}

/* Optional outgoing modifier */

.pm-message--own {
  grid-template-columns: minmax(0, 1fr) 38px;
}

.pm-message--own .pm-message__avatar {
  order: 2;
}

.pm-message--own .pm-message__content {
  order: 1;
  justify-self: end;
}

.pm-message--own .pm-message__bubble {
  background: var(--accent-main-soft);
  border-color: transparent;
  border-top-left-radius: 17px;
  border-top-right-radius: 9px;
}

.pm-message--own .pm-message__author {
  display: none;
}

/* =========================
   QUOTES INSIDE MESSAGE
   ========================= */

.pm-message__text blockquote,
.pm-message__text .quote,
.pm-message__text fieldset {
  margin: 10px 0 0;
  padding: 11px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-main);
  border-radius: 13px;
  color: var(--text);
  box-shadow: none;
  font-size: 13px;
  line-height: 1.6;
}

.pm-message__text .title_quote,
.pm-message__text .quote_title,
.pm-message__text .quoteheader,
.pm-message__text .quote-header,
.pm-message__text .quote__title,
.pm-message__text legend,
.pm-message__text cite {
  display: none !important;
}

/* =========================
   MESSAGE MENU
   ========================= */

.pm-message__menu-wrap {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 8;
}

.pm-message__menu-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text-fade);
  cursor: pointer;
  opacity: 0;
  transform: translateY(-2px);
  transition:
    opacity 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease,
    transform 0.18s ease;
}

.pm-message:hover .pm-message__menu-btn,
.pm-message__menu-wrap.is-open .pm-message__menu-btn,
.pm-message__menu-btn:focus-visible {
  opacity: 1;
  transform: translateY(0);
}

.pm-message__menu-btn:hover {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.pm-message__menu-btn:active {
  transform: scale(0.96);
}

.pm-message__menu-btn .i-svg {
  width: 16px;
  height: 16px;
}

.pm-message__menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 190px;
  display: grid;
  gap: 4px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.10);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(6px) scale(0.98);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease,
    visibility 0.18s ease;
}

.theme-dark .pm-message__menu {
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.26);
}

.pm-message--own .pm-message__menu {
  left: auto;
  right: 0;
}

.pm-message__menu-wrap.is-open .pm-message__menu {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.pm-message__menu a {
  color: inherit;
  text-decoration: none;
}

.pm-message__menu-item {
  width: 100%;
  min-height: 38px;
  padding: 0 11px;
  display: flex;
  align-items: center;
  gap: 9px;
  background: transparent;
  border: 0 !important;
  border-radius: 11px;
  box-shadow: none !important;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  line-height: 1.2;
  font-weight: 600;
  text-align: left;
  transition:
    background 0.18s ease,
    color 0.18s ease;
}

.pm-message__menu-item .i-svg {
  width: 15px;
  height: 15px;
  color: var(--text-soft);
}

.pm-message__menu a:hover .pm-message__menu-item,
.pm-message__menu-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.pm-message__menu-item--danger {
  color: var(--danger);
}

.pm-message__menu-item--danger .i-svg {
  color: var(--danger);
}

.pm-message__menu a:hover .pm-message__menu-item--danger,
.pm-message__menu-item--danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* =========================
   REPLY COMPOSER
   ========================= */

.pm-reply {
  padding: 0 18px 18px;
  background: var(--surface);
}

.pm-reply__shell {
  position: relative;
}

.pm-reply__composer {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.pm-reply__composer:focus-within {
  background: var(--surface);
  border-color: rgba(45, 123, 255, 0.34);
  box-shadow: 0 0 0 3px rgba(45, 123, 255, 0.08);
}

.pm-reply__input {
  width: 100%;
  min-height: 54px;
  max-height: 170px;
  display: block;
  padding: 14px 56px 14px 48px;
  background: transparent;
  border: 0 !important;
  border-radius: 20px;
  box-shadow: none !important;
  color: var(--text);
  resize: none;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.55;
}

.pm-reply__input:focus {
  outline: none !important;
  box-shadow: none !important;
}

.pm-reply__input::placeholder {
  color: var(--text-fade);
}

.pm-reply__controls {
  position: absolute;
  left: 9px;
  right: 9px;
  bottom: 8px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.pm-reply__emoji,
.pm-reply__send {
  pointer-events: auto;
  border: 0 !important;
  outline: 0 !important;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.16s ease,
    color 0.16s ease,
    transform 0.16s ease;
}

.pm-reply__emoji {
  width: 34px;
  height: 34px;
  background: transparent;
  border-radius: 12px;
  color: var(--text-soft);
}

.pm-reply__emoji:hover {
  background: var(--surface);
  color: var(--text);
}

.pm-reply__emoji:active {
  transform: scale(0.96);
}

.pm-reply__send {
  width: 36px;
  height: 36px;
  background: var(--accent-main);
  border-radius: 13px;
  color: #fff;
}

.pm-reply__send:hover {
  background: var(--accent-main-hover);
}

.pm-reply__send:active {
  transform: scale(0.96);
}

.pm-reply__emoji .i-svg,
.pm-reply__send .i-svg {
  width: 16px;
  height: 16px;
}

/* =========================
   EMOJI PANEL
   ========================= */

.pm-reply__emoji-panel {
  position: absolute;
  left: 8px;
  bottom: calc(100% + 10px);
  z-index: 20;
  width: min(320px, calc(100vw - 40px));
  display: none;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 12px 34px rgba(16, 24, 40, 0.12);
}

.theme-dark .pm-reply__emoji-panel {
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.28);
}

.pm-reply__emoji-panel.is-open {
  display: grid !important;
}

.pm-reply__emoji-item {
  width: 100%;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font-size: 21px;
  transition:
    background 0.16s ease,
    transform 0.16s ease;
}

.pm-reply__emoji-item:hover {
  background: var(--surface-3);
}

.pm-reply__emoji-item:active {
  transform: scale(0.96);
}

/* =========================
   DARK
   ========================= */

.theme-dark .pm-compose__input,
.theme-dark .pm-compose__editor,
.theme-dark .pm-compose__captcha,
.theme-dark .pm-reply__composer,
.theme-dark .pm-message__bubble {
  background: rgba(255, 255, 255, 0.03);
}

.theme-dark .pm-message__menu-btn {
  background: rgba(32, 36, 43, 0.72);
}

.theme-dark .pm-compose__captcha-image,
.theme-dark .pm-message__text blockquote,
.theme-dark .pm-message__text .quote,
.theme-dark .pm-message__text fieldset {
  background: rgba(255, 255, 255, 0.04);
}

.theme-dark #pmlist table.pm tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

/* =========================
   RESPONSIVE
   ========================= */

@media screen and (max-width: 768px) {
  .pm-page {
    gap: 12px;
    margin-bottom: 14px;
  }

  .pm-card,
  .pm-chat {
    border-radius: 20px;
  }

  .pm-card--hero-compact {
    padding: 13px 15px;
  }

  .pm-card__hero-title {
    font-size: 22px;
  }

  .pm-toolbar__icon-btn,
  .pm-card__hero-back,
  .pm-card__hero-action {
    width: 36px;
    height: 36px;
    border-radius: 12px;
  }

  .pm-card--dialogs {
    padding: 10px;
  }

  #pmlist table.pm tbody tr {
    min-height: 68px;
    grid-template-columns: 42px minmax(0, 1fr) !important;
    gap: 10px;
    padding: 8px 10px !important;
    border-radius: 15px;
  }

  .pm-dialog__avatar {
    width: 42px;
    height: 42px;
  }

  .pm-section-head {
    padding: 18px 18px 0;
  }

  .pm-section-head__title {
    font-size: 20px;
  }

  .pm-compose {
    padding: 16px 18px 0;
  }

  .pm-compose__top {
    grid-template-columns: 1fr;
  }

  .pm-compose__footer {
    align-items: stretch;
    flex-direction: column;
  }

  .pm-compose__captcha {
    width: 100%;
    min-width: 0;
  }

  .pm-compose__actions {
    width: 100%;
  }

  .pm-compose__btn {
    flex: 1 1 auto;
  }

  .pm-chat__body {
    padding: 16px;
  }

  .pm-message {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 9px;
  }

  .pm-message--own {
    grid-template-columns: minmax(0, 1fr) 34px;
  }

  .pm-message__avatar,
  .pm-message__avatar-cover {
    width: 34px;
    height: 34px;
  }

  .pm-message__content {
    max-width: min(100%, 520px);
  }

  .pm-message__menu-btn {
    opacity: 1;
    transform: none;
  }

  .pm-message__menu {
    position: fixed;
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    z-index: 1010;
    width: 100%;
    min-width: 0;
    padding: 14px 14px calc(16px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -18px 46px rgba(0, 0, 0, 0.18);
    opacity: 1;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(100%);
  }

  .pm-message__menu-wrap.is-open .pm-message__menu {
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
  }

  .pm-reply {
    padding: 0 16px 16px;
  }
}

@media screen and (max-width: 640px) {
  .pm-page {
    gap: 10px;
    margin-bottom: 12px;
  }

  .pm-card,
  .pm-chat {
    border-radius: 18px;
  }

  .pm-card--hero-compact {
    padding: 12px 14px;
  }

  .pm-card__hero-row {
    gap: 10px;
  }

  .pm-card__hero-title {
    font-size: 20px;
  }

  .pm-card__hero-left--with-back,
  .pm-card__hero-left--dialog,
  .pm-card__hero-user,
  .pm-card__hero-actions,
  .pm-toolbar__nav--iconbar {
    gap: 6px;
  }

  .pm-card__hero-user-avatar {
    width: 34px;
    height: 34px;
  }

  .pm-card__hero-user-name,
  .pm-card__hero-user-name a {
    font-size: 14px;
  }

  .pm-toolbar__icon-btn,
  .pm-card__hero-back,
  .pm-card__hero-action {
    width: 34px;
    height: 34px;
    border-radius: 11px;
  }

  .pm-card--dialogs {
    padding: 8px;
  }

  #pmlist table.pm tbody {
    gap: 7px;
  }

  #pmlist table.pm tbody tr {
    min-height: 64px;
    grid-template-columns: 38px minmax(0, 1fr) !important;
    gap: 9px;
    padding: 8px 9px !important;
    border-radius: 14px;
  }

  .pm-dialog__avatar {
    width: 38px;
    height: 38px;
    font-size: 13px;
  }

  .pm-dialog__name {
    font-size: 13px;
  }

  .pm-dialog__time {
    font-size: 10px;
  }

  .pm-dialog__preview {
    font-size: 11px;
  }

  .pm-section-head {
    padding: 16px 14px 0;
  }

  .pm-compose {
    padding: 14px 14px 0;
    gap: 14px;
  }

  .pm-compose__input {
    min-height: 48px;
    border-radius: 14px;
  }

  .pm-compose__editor {
    padding: 10px;
    border-radius: 16px;
  }

  .pm-compose__editor textarea,
  .pm-compose__editor .wseditor,
  .pm-compose__editor .bb-editor textarea {
    min-height: 160px !important;
    border-radius: 14px !important;
  }

  .pm-compose__actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .pm-compose__btn {
    width: 100%;
    min-height: 42px;
    border-radius: 13px;
    font-size: 13px;
  }

  .pm-chat__body {
    gap: 12px;
    padding: 14px 12px;
  }

  .pm-message {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 8px;
  }

  .pm-message--own {
    grid-template-columns: minmax(0, 1fr) 32px;
  }

  .pm-message__avatar,
  .pm-message__avatar-cover {
    width: 32px;
    height: 32px;
  }

  .pm-message__online {
    width: 11px;
    height: 11px;
  }

  .pm-message__bubble {
    padding: 10px 12px 9px;
    border-radius: 15px;
    border-top-left-radius: 8px;
  }

  .pm-message--own .pm-message__bubble {
    border-radius: 15px;
    border-top-right-radius: 8px;
  }

  .pm-message__author {
    font-size: 12px;
  }

  .pm-message__text {
    font-size: 13px;
    line-height: 1.62;
  }

  .pm-message__date-inside {
    font-size: 10px;
  }

  .pm-message__menu-btn {
    width: 26px;
    height: 26px;
  }

  .pm-message__menu {
    padding: 14px 14px calc(16px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
  }

  .pm-message__menu-item {
    min-height: 40px;
    padding: 0 11px;
    border-radius: 11px;
    font-size: 13px;
  }

  .pm-reply {
    padding: 0 12px 12px;
  }

  .pm-reply__composer {
    border-radius: 18px;
  }

  .pm-reply__input {
    min-height: 50px;
    max-height: 150px;
    padding: 12px 50px 12px 44px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
  }

  .pm-reply__controls {
    left: 7px;
    right: 7px;
    bottom: 7px;
  }

  .pm-reply__emoji {
    width: 30px;
    height: 30px;
    border-radius: 10px;
  }

  .pm-reply__send {
    width: 34px;
    height: 34px;
    border-radius: 12px;
  }

  .pm-reply__emoji-panel {
    left: 0;
    width: min(300px, calc(100vw - 24px));
    gap: 7px;
    padding: 9px;
    border-radius: 16px;
  }

  .pm-reply__emoji-item {
    min-height: 38px;
    border-radius: 10px;
    font-size: 20px;
  }
}

/* =========================
   REDUCED MOTION
   ========================= */

@media (prefers-reduced-motion: reduce) {
  .pm-toolbar__icon-btn,
  .pm-card__hero-back,
  .pm-card__hero-action,
  #pmlist table.pm tbody tr,
  .pm-compose__input,
  .pm-compose__btn,
  .pm-message__menu-btn,
  .pm-message__menu,
  .pm-reply__composer,
  .pm-reply__emoji,
  .pm-reply__send,
  .pm-reply__emoji-item {
    transition: none !important;
  }
}