/* Игровой экран, часть 4/6: чат (#chat и его содержимое).
   См. 03-game-fx.css — общее примечание про разрез бывшего 03-game.css. */

#chat {
  position: fixed;
  right: calc(12px + var(--sa-right));
  bottom: calc(12px + var(--sa-bottom));
  z-index: var(--z-chat);
  width: min(420px, calc(100vw - 24px));
  border: 1px solid var(--border2);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--panel) calc(var(--hud-panel-alpha) * 100%), transparent);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-float);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: calc(100dvh - 24px - var(--sa-top) - var(--sa-bottom));
}

#chatHeader {
  padding: var(--pad-md);
  font-size: var(--fs-meta);
  color: var(--muted);
  user-select: none;
  cursor: pointer;
  border-bottom: 1px solid var(--border2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#chatHeaderLeft {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

#chatHeaderTitle {
  color: rgba(255, 255, 255, 0.90);
  font-weight: 800;
}

.chatHeaderStatus {
  font-size: var(--fs-meta);
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

#chatHeaderRight {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chatCollapseBtn {
  width: var(--control-h);
  height: var(--control-h);
  font-size: var(--fs-body);
}

#chatLog {
  height: auto;
  flex: 1;
  min-height: 140px;
  max-height: var(--chat-log-max, 320px);
  overflow-y: auto;
  padding: var(--pad-md);
  font-size: var(--fs-meta);
  line-height: 1.45;
  white-space: normal;
  -webkit-overflow-scrolling: touch;
}

#chat.chatEmpty #chatLog {
  min-height: 80px;
}

.chatLine {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.14);
}

.chatLine + .chatLine {
  margin-top: 8px;
}

.chatMeta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.chatName {
  font-weight: 800;
  color: rgba(255, 255, 255, 0.92);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chatTime {
  flex: 0 0 auto;
  font-size: var(--fs-meta);
  font-variant-numeric: tabular-nums;
  color: rgba(229, 231, 235, 0.62);
}

.chatText {
  color: rgba(255, 255, 255, 0.86);
  word-break: break-word;
}

#chatForm {
  display: flex;
  gap: 8px;
  padding: var(--pad-md);
  border-top: 1px solid var(--border2);
}

#emojiBtn {
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--btn);
}

#chatInputWrap {
  flex: 1;
  position: relative;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--panel2);
}

#chatInput {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: none;
  background: transparent;
  color: var(--text);
  outline: none;
  resize: none;
  min-height: 36px;
  line-height: 1.35;
}

#chatInput:focus-visible {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent);
}

#chatBtn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#chatBtn:focus-visible {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent);
}

.badge {
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 90%, transparent);
  color: #fff;
  font-size: var(--fs-meta);
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.badge.hidden {
  display: none;
}

#rightInfo .rightDetailsSummary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#rightInfo .rightDetailsSummary .badge {
  flex: 0 0 auto;
}

.rightEmpty {
  padding: 10px 10px 12px;
  display: grid;
  gap: 4px;
}

.rightEmptyTitle {
  font-size: var(--fs-meta);
  font-weight: 800;
  color: rgba(255, 255, 255, 0.86);
}

.rightEmptyDesc {
  font-size: var(--fs-meta);
  font-weight: 700;
  color: var(--muted);
}

.rightEmpty.hidden {
  display: none;
}

#emojiPanel {
  display: none;
  padding: 8px 8px 10px;
  border-top: 1px solid var(--border2);
  max-height: 210px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  /* Панель — флекс-ребёнок #chat (overflow: hidden, max-height). Без
     flex-shrink: 0 её сжимало до полоски в 18px и выталкивало за нижний
     край: кнопка 😀 «не работала», хотя класс .open ставился. */
  flex: 0 0 auto;
}

/* Пока панель открыта, лог отдаёт ей высоту: бюджет #chat фиксирован
   (шапка + форма + лог 140px уже забирали его целиком), а лог под панелью
   в этот момент всё равно не читают. */
#chat:has(#emojiPanel.open) #chatLog {
  min-height: 0;
  flex: 0 1 auto;
}

#chat.collapsed #chatLog,
#chat.collapsed #chatForm,
#chat.collapsed #emojiPanel {
  display: none;
}

#chat.collapsed {
  min-height: 0;
}

