/* Базовые компоненты и состояния. Замещённые свойства удалены при консолидации 2.9. */
#chat-panel {
  grid-area: chat;
  min-width: 0;
  position: sticky;
  top: 24px;
  height: min(690px, calc(100dvh - 48px));
  min-height: 360px;
  display: flex;
  flex-direction: column;
  align-self: start;
  border: 1px solid #303034;
  border-radius: 26px;
  background: #030303;
  overflow: hidden;
}
.chat-heading-icon {
  display: none;
}
.chat-history-icon {
  margin-left: auto;
}
.chat-close {
  display: none !important;
}
.chat-toolbar {
  display: none;
}
.chat-hint {
  font-size: var(--text-xs);
  color: #aaa;
}
.chat-date {
  width: fit-content;
  margin: 6px auto 10px;
  font-size: 11px;
  color: #909096;
  padding: 4px 10px;
  background: #171717;
  border-radius: var(--radius);
}
.message-avatar .identity {
  padding: 0;
  border: 0;
  background: none;
  border-radius: 50%;
  overflow: visible;
  gap: 0;
}
.message-avatar .identity-name {
  display: none;
}
.avatar-tone-0 {
  background: #6155f5;
}
.avatar-tone-1 {
  background: #cb30e0;
}
.avatar-tone-2 {
  background: #00b7c5;
}
.avatar-tone-3 {
  background: #ff2d55;
}
.avatar-tone-4 {
  background: #df6f28;
}
.avatar-tone-5 {
  background: #8b68d9;
}
.avatar-tone-6 {
  background: #308a7d;
}
.avatar-tone-7 {
  background: #387fd2;
}
.avatar-color-0 {
  background: #ff7675;
}
.avatar-color-1 {
  background: #fdcb6e;
}
.avatar-color-2 {
  background: #55efc4;
}
.avatar-color-3 {
  background: #74b9ff;
}
.avatar-color-4 {
  background: #a29bfe;
}
.avatar-color-5 {
  background: #fd79a8;
}
.avatar-color-6 {
  background: #fab1a0;
}
.avatar-color-7 {
  background: #81ecec;
}
.avatar-color-8 {
  background: #ffeaa7;
}
.avatar-color-9 {
  background: #ff9f43;
}
.avatar-color-10 {
  background: #00b894;
}
.avatar-color-11 {
  background: #0984e3;
}
.avatar-color-12 {
  background: #6c5ce7;
}
.avatar-color-13 {
  background: #e84393;
}
.avatar-color-14 {
  background: #d63031;
}
.avatar-color-15 {
  background: #e17055;
}
.message header {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 2px;
  min-height: 21px;
}
.message header .mention-name {
  padding: 0;
  min-height: 24px;
  min-width: 0;
  max-width: 100%;
  text-align: left;
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.35;
  color: #fff;
}
.message header .identity {
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  border-radius: 0;
  gap: 0;
  max-width: 100%;
  min-width: 0;
}
.message header .identity-avatar {
  display: none;
}
.message header .identity-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.message header .identity-name small {
  font-size: 10px;
  color: #ad92c0;
  line-height: 1.3;
}
.message time {
  font-weight: 400;
}
.message-report {
  padding: 0;
  min-height: 24px;
  min-width: 22px;
  align-self: start;
  color: #85858a;
  margin-left: auto;
  font-size: var(--title-sm);
  line-height: 1;
  opacity: 0.7;
}
.message-report:hover {
  color: #fff;
  opacity: 1;
}
.message-report-placeholder {
  pointer-events: none;
  user-select: none;
}
.message-meta {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  color: #aaa;
  font-size: 11px;
  line-height: 1.2;
  margin-top: 2px;
}
.message-sent {
  color: #b5c681;
  font-size: 11px;
}
.message.mine {
  justify-content: flex-start;
}
.mine .mention-name {
  display: block;
}
.mine .identity-name {
  color: #dcfe73;
}
.grouped .message-avatar {
  visibility: hidden;
  min-height: 0;
  height: 0;
  /* Вертикальные padding и border иначе оставляют ненулевой размер border-box. */
  padding-block: 0;
  border-block-width: 0;
}
.grouped .mention-name {
  display: none !important;
}
.grouped header {
  min-height: 0;
  height: 0;
  overflow: visible;
  margin: 0;
  justify-content: flex-end;
}
.grouped header time {
  display: none;
}
.grouped .message-report {
  opacity: 0.25;
  transform: translateY(-2px);
}
.grouped p {
  padding-right: 18px;
}
.system-message {
  display: block;
  margin: 16px auto;
  max-width: 90%;
  width: fit-content;
  padding: 6px 10px;
  border-radius: 10px;
  background: #181818;
  text-align: center;
}
.system-message time {
  display: none;
}
.chat-empty {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 24px;
  gap: 12px;
  flex: 1;
  min-height: 180px;
  color: #a4a4ab;
}
.chat-empty svg {
  width: 36px;
  height: 36px;
  color: #65656c;
}
.chat-empty strong {
  font-size: var(--text-base);
  line-height: 1.5;
  color: #dedee1;
}
.chat-empty p {
  font-size: var(--text-sm);
  line-height: 1.5;
  max-width: 230px;
}
.chat-auth.primary {
  min-height: 42px;
  font-size: var(--text-sm);
}
.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.emoji-toggle:hover,
.emoji-toggle[aria-expanded="true"] {
  color: #fff;
  border-color: #777;
}
.emoji-bar {
  position: absolute;
  z-index: 4;
  left: 10px;
  bottom: 66px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 138px;
  padding: 6px;
  gap: 0;
  background: #252528;
  border: 1px solid #37373b;
  border-radius: var(--radius);
  box-shadow: 0 8px 30px #0008;
}
.emoji-bar button {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 38px;
  padding: 6px;
  border-radius: 8px;
}
.emoji-bar button:hover {
  background: #fff2;
}
.emoji-bar svg {
  width: 25px;
  height: 25px;
  stroke: #564027;
  stroke-width: 1.1;
}
.chat-input {
  gap: 8px;
}
.chat-input:focus-within {
  border-color: #7b7b80;
}
.chat-input textarea {
  flex: 1;
  min-width: 0;
  outline: none;
  font-weight: 400;
}
.chat-input textarea::placeholder {
  color: #aaa;
}
@media (hover: hover) and (pointer: fine) {
  .chat-input button:hover {
    background: var(--accent);
  }
}
.chat-input button svg {
  width: 22px;
  height: 22px;
  stroke-width: 2;
}
.chat-new {
  position: absolute;
  right: 16px;
  bottom: 76px;
  z-index: 3;
  min-width: 36px;
  border-radius: 22px;

  background: #252527;
  color: #e2e2e5;
  border: 1px solid #3e3e41;
  box-shadow: 0 4px 12px #0005;
  font-size: var(--text-xs);
}
.mention-suggestions {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 70px;
  max-height: 190px;
  overflow: auto;
  z-index: 5;
  border: 1px solid #4c4250;
  border-radius: var(--radius);
  background: #252229;
  padding: 6px;
  box-shadow: 0 12px 30px #0007;
}
.mention-suggestions button {
  display: block;
  width: 100%;
  text-align: left;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: var(--text-sm);
}
.mention-suggestions button:hover {
  background: #fff1;
}
.delivery-meta {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  color: #aaa;
  margin-top: 4px;
  line-height: 1.4;
}
.delivery-meta .text-button {
  min-height: 30px;
  font-size: var(--text-xs);
  color: var(--accent);
  padding: 2px;
}
.failed .delivery-meta,
.retry .delivery-meta {
  color: #ff9cb6;
}
.optimistic.failed,
.optimistic.retry {
  border-right: 2px solid var(--danger);
  padding-right: 8px;
}
#chat-game-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #201b24;
  padding: 8px 12px;
  border-bottom: 1px solid #3a2c41;
  font-size: var(--text-xs);
  flex: none;
}
#chat-game-status button {
  font-size: var(--text-xs);
  min-height: 36px;
  color: var(--accent);
  white-space: nowrap;
}
@media (min-width: 1121px) {
  .home-layout #chat-panel {
    position: relative;
    top: 0;
    height: 402px;
    min-height: 402px;
  }
  .home-layout .chat-header {
    min-height: 42px;
    padding: 5px 14px;
  }
  .home-layout .chat-header h2 {
    font-size: var(--text-sm);
  }
  .home-layout .chat-channel {
    display: none;
  }
  /* Отступы истории и дат общие для всех вкладок, чтобы сообщения не смещались. */
}
@media (max-width: 1120px) {
  #chat-panel {
    position: fixed;
    right: 16px;
    top: calc(var(--chat-top, 0px) + 16px);
    z-index: 100;
    width: min(420px, calc(100% - 32px));
    height: calc(var(--chat-viewport, 100dvh) - 32px);
    min-height: 0;
    visibility: hidden;
    transform: translateX(calc(100% + 24px));
  }
  #chat-panel.open {
    visibility: visible;
    transform: none;
  }
  #chat-panel.chat-animated {
    transition:
      transform 0.2s ease,
      visibility 0.2s;
  }
  .chat-close {
    display: grid !important;
    place-items: center;
  }
  .chat-open {
    overflow: hidden;
  }
}
@media (max-width: 760px) {
  #chat-panel {
    width: 100%;
    right: 0;
    top: var(--chat-top, 0px);
    height: var(--chat-viewport, 100dvh);
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .message {
    margin-top: 18px;
  }
  .chat-input textarea {
    padding-top: 7px;
  }
  .chat-new {
    bottom: calc(82px + env(safe-area-inset-bottom));
  }
  .emoji-bar {
    left: 12px;
    bottom: calc(72px + env(safe-area-inset-bottom));
  }
  .mention-suggestions {
    bottom: calc(76px + env(safe-area-inset-bottom));
  }
  .chat-empty {
    min-height: 180px;
  }
}
@media (max-height: 500px) and (max-width: 1120px) {
  #chat-form {
    padding-top: 6px;
    padding-bottom: 6px;
  }
  .emoji-bar {
    bottom: 62px;
  }
  .message {
    margin-top: 12px;
  }
  #messages {
    padding-block: 8px;
  }
}
/* Чат: открытые строки на общем фоне, стабильный ритм и крупные действия. */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  flex: none;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #141711;
}
.chat-header h2 {
  font-size: var(--text-base);
  line-height: 1.3;
  letter-spacing: 0;
}
.chat-channel {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  line-height: 18px;
  color: var(--muted);
  margin-top: 2px;
}
.chat-header .icon-button {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: var(--touch-h);
  padding: 10px;
  border: 0;
  background: none;
  color: var(--muted);
}
#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 12px 20px;
  scrollbar-width: thin;
  scrollbar-color: #3b4136 transparent;
  overflow-anchor: none;
}
.message {
  display: flex;
  align-items: flex-start;
  position: relative;
  gap: 12px;
  margin: 8px 0 0;
  padding: 0;
  min-width: 0;
  border: 0;
  background: none;
}
.message-avatar {
  flex: none;
  align-self: flex-start;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: var(--touch-h);
  margin: 0;
  padding: 2px;
  border: 0;
}
.message-avatar .identity-avatar {
  width: 40px;
  height: 40px;
  min-width: 40px;
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 700;
  border: 1px solid #fff3;
}
.message-bubble {
  flex: 1;
  min-width: 0;
  max-width: calc(100% - 56px);
  padding: 0;
  border-radius: 0;
  background: none !important;
  box-shadow: none;
}
.message header .identity-name {
  display: block;
  min-width: 0;
  max-width: 100%;
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1.5;
}
.message p {
  font-size: var(--text-base);
  line-height: 1.5;
  color: #f4f5ef;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message time {
  color: #a0a69a;
  font-size: var(--text-xs);
  line-height: 18px;
  white-space: nowrap;
  flex: none;
}
.message.grouped {
  margin-top: 0;
}
.mentioned {
  background: #d7fe3910;
  border-radius: 10px;
  padding: 8px;
  margin-inline-start: -5px;
  border-left: 3px solid #cdff00;
  padding-left: 2px;
}
.mentioned .message-bubble {
  max-width: calc(100% - 56px);
}
.system-message p {
  color: #aeb4a5;
  font-size: var(--text-xs);
  line-height: 18px;
}
#chat-form {
  position: relative;
  padding: 6px 12px;
  flex: none;
  background: #080a07;
  border-top: 1px solid var(--line);
  gap: 0;
}
.chat-input {
  display: flex;
  align-items: flex-end;
  flex: 1;
  min-width: 0;
  min-height: 52px;
  padding: 3px;
  border: 1px solid #3b4232;
  border-radius: 28px;
  background: #20241b;
}
.chat-input textarea {
  min-height: var(--touch-h);
  max-height: 120px;
  padding: 10px 8px 10px 12px;
  border: 0;
  border-radius: 0;
  color: var(--ink);
  background: none;
  box-shadow: none;
  font-size: var(--text-base);
  line-height: 24px;
  resize: none;
}
.chat-input button {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  min-height: var(--touch-h);
  padding: 10px;
  border: 0;
  border-radius: 50%;
  background: #eef2e6;
  color: #151a0e;
}
.chat-input button:disabled {
  background: #5c6550;
  color: #d3dac9;
}
@media (hover: none), (pointer: coarse) {
  .chat-input button:not(:disabled) {
    background: #eef2e6;
    color: #151a0e;
  }
}
.emoji-toggle {
  line-height: 1;
  margin: 0;
  align-self: center;
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: var(--touch-h);
  padding: 0;
  border: 1px solid #394230;
  border-radius: 50%;
  color: var(--muted);
  background: #171c13;
  font-size: var(--title-md);
  font-weight: 400;
}
.emoji-toggle .ui-icon { display: block; width: 22px; height: 22px; margin: 0; }
.composer-hint {
  display: none;
}
.chat-auth {
  margin: 12px;
  flex: none;
  min-height: var(--touch-h);
}
.chat-new {
  min-height: var(--touch-h);
}
@media (max-width: 760px) {
  .chat-header {
    min-height: 68px;
    padding: 12px 16px;
  }
  #messages {
    padding: 12px 16px 20px;
  }
  #chat-form {
    padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
  }
  .chat-new {
    bottom: calc(88px + env(safe-area-inset-bottom));
  }
  .mention-suggestions {
    bottom: calc(88px + env(safe-area-inset-bottom));
  }
}
@media (max-height: 500px) and (max-width: 1120px) {
  .chat-header {
    min-height: 56px;
    padding: 6px 12px;
  }
  #chat-form {
    padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
  }
}

/* 2.11.7: мобильный чат полностью изолирован от страницы и iOS-клавиатуры. */
@media (max-width: 1120px) {
  body.chat-open {
    /* Не вмешиваемся в высоту нижней навигации: Safari/Gboard используют собственную панель над клавиатурой. */
    background: #000;
    overscroll-behavior: none;
  }

  body.chat-open::before {
    content: "";
    position: fixed;
    left: 0;
    right: 0;
    top: -100vh;
    bottom: -100vh;
    z-index: 99;
    background: #000;
    opacity: calc(1 - var(--chat-swipe-progress, 0));
    pointer-events: none;
  }

  #chat-panel {
    width: 100%;
    right: 0;
    top: var(--chat-top, 0px);
    height: var(--chat-viewport, 100dvh);
    max-height: var(--chat-viewport, 100dvh);
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: #000;
    overscroll-behavior: none;
    touch-action: pan-y;
  }

  #chat-panel.chat-swipe-active,
  #chat-panel.chat-swipe-settling {
    will-change: transform;
  }

  #chat-panel.chat-swipe-active {
    transition: none !important;
  }

  #chat-panel.chat-swipe-active #messages {
    overflow-y: hidden;
    touch-action: none;
  }

  #chat-form {
    background: #080a07;
  }

  /* При клавиатуре убираем наш safe-area отступ: дальше начинается уже системный интерфейс Safari. */
  body.chat-open.chat-input-focused #chat-form {
    padding-bottom: 6px;
  }
}

/* Одна плавающая кнопка: стрелка вниз без новых сообщений, счётчик + стрелка при новых. */
.chat-new {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  height: 44px;
  padding: 0 12px;
}
.chat-new svg {
  width: 20px;
  height: 20px;
  stroke-width: 2;
}
.chat-new-count {
  min-width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--accent);
  color: #11150c;
  font-size: 11px;
  font-weight: 800;
  line-height: 20px;
}

/* Разделитель остаётся в DOM для существующей логики непрочитанных. */
.chat-unread-line { display: none; }
.emoji-bar { grid-template-columns: repeat(4, 1fr); width: 184px; }
.emoji-bar button { font-size: 24px; line-height: 1; min-height: 44px; }

/* На ПК уменьшаем аватары; на сенсорном экране сохраняем область нажатия 44 px. */
@media (min-width:1121px) {
  .message { gap: 8px; }
  .message-avatar { width: 32px; height: 32px; min-height: 32px; padding: 0; }
  .message-avatar .identity-avatar { width: 32px; height: 32px; min-width: 32px; }
  .message-bubble, .mentioned .message-bubble { max-width: calc(100% - 40px); }
}
