/* =============================================================================
   GAME-CHAT — side-panel модалка для admin↔developer чата.
   Backdrop затемнённый, panel справа на 420px ширины, full-height.
   ========================================================================= */

.chat-panel-back {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 900;
  display: flex;
  justify-content: flex-end;
}

.chat-panel {
  width: 100%;
  max-width: 460px;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border-2);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(20, 40, 32, 0.4);
}

.chat-head-titles { flex: 1; min-width: 0; }
.chat-head-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-head-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.chat-close-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
  font-family: inherit;
  flex-shrink: 0;
}
.chat-close-btn:hover { color: var(--text); }
@media (hover: none) {
  .chat-close-btn { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
}

/* Admin-only top bar with hide/show toggle + status. */
.chat-admin-bar {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-2);
  background: rgba(60, 45, 14, 0.25);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
}
.chat-status {
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.chat-status.hidden { color: #ffb89a; }
.chat-status.visible { color: #b6efd2; }
.chat-toggle-hide {
  padding: 4px 10px;
  font-size: 11px;
}
@media (hover: none) {
  .chat-toggle-hide { min-height: 44px; }
}

/* Messages scrollable list. */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-2, #0e1110);
}
.chat-empty {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: auto 0;
  padding: 40px 16px;
}

/* Message bubble. mine = right-aligned; theirs = left. */
.chat-msg {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 12px;
  position: relative;
  word-wrap: break-word;
}
.chat-msg.mine {
  align-self: flex-end;
  background: linear-gradient(180deg, rgba(60, 130, 110, 0.45), rgba(28, 80, 60, 0.7));
  border: 1px solid rgba(110, 180, 160, 0.4);
  color: #e6f5ed;
}
.chat-msg.theirs {
  align-self: flex-start;
}
/* Theirs: разные цвета по role'у. */
.chat-msg.theirs.role-admin {
  background: linear-gradient(180deg, rgba(217, 160, 98, 0.22), rgba(60, 40, 14, 0.55));
  border: 1px solid rgba(217, 160, 98, 0.45);
  color: #ffe2c0;
}
.chat-msg.theirs.role-developer {
  background: linear-gradient(180deg, rgba(95, 168, 211, 0.22), rgba(20, 42, 60, 0.55));
  border: 1px solid rgba(95, 168, 211, 0.45);
  color: #d6ecf7;
}

.chat-msg-meta {
  font-size: 10px;
  margin-bottom: 4px;
  color: var(--muted);
  display: flex;
  gap: 8px;
  align-items: baseline;
  opacity: 0.85;
}
.chat-msg-author {
  font-weight: 700;
  color: inherit;
}
.chat-msg-time {
  font-variant-numeric: tabular-nums;
}
.chat-msg-body {
  font-size: 13px;
  line-height: 1.42;
  white-space: pre-wrap;
}

/* Input row at bottom. */
.chat-input-row {
  padding: 10px 14px;
  border-top: 1px solid var(--border-2);
  background: var(--surface);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  font: inherit;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-2);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  outline: none;
  resize: vertical;
  min-height: 40px;
  max-height: 200px;
  transition: border-color 0.12s ease;
}
.chat-input:focus {
  border-color: rgba(110, 180, 160, 0.55);
}
.chat-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.chat-send-btn {
  padding: 8px 16px;
  flex-shrink: 0;
}

/* =============================================================================
   Chat-open button on the game title-line.
   ========================================================================= */
.chat-open-btn {
  padding: 4px 10px;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chat-open-btn.admin {
  background: linear-gradient(180deg, rgba(217, 160, 98, 0.22), rgba(60, 40, 14, 0.55));
  border-color: rgba(217, 160, 98, 0.5);
  color: #ffe2c0;
}
.chat-open-btn.admin:hover {
  background: linear-gradient(180deg, rgba(217, 160, 98, 0.42), rgba(80, 56, 18, 0.7));
}
.chat-open-btn.owner {
  background: linear-gradient(180deg, rgba(95, 168, 211, 0.22), rgba(20, 42, 60, 0.55));
  border-color: rgba(95, 168, 211, 0.5);
  color: #d6ecf7;
}
.chat-open-btn.owner:hover {
  background: linear-gradient(180deg, rgba(95, 168, 211, 0.42), rgba(30, 60, 82, 0.7));
}

/* =============================================================================
   Mobile adaptive — chat panel
   ========================================================================= */
@media (max-width: 640px) {
  .chat-panel-back {
    /* Prevent bottom content from being hidden under iOS home bar. */
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .chat-panel {
    max-width: 100%;
    height: 100%;
    height: 100dvh; /* fallback: height:100% already covers 100vh via parent */
  }
  .chat-input {
    font-size: 16px; /* prevent iOS auto-zoom on focus (overrides 13px in this file) */
  }
  .chat-input-row {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .chat-close-btn {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* =============================================================================
   Sidebar unread badge — red dot/count on «Мои игры» icon.
   ========================================================================= */
.side .nav .icon-btn.has-chat-unread {
  position: relative;
}
.side .nav .icon-btn.has-chat-unread::after {
  content: attr(data-chat-unread);
  position: absolute;
  top: 2px; right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: #c83a3a;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  border: 1px solid #1a1a1a;
  box-shadow: 0 0 4px rgba(200, 58, 58, 0.6);
  font-variant-numeric: tabular-nums;
}

/* =============================================================================
   Per-tile unread badge for my-games tiles.
   ========================================================================= */
.my-tile .tile-chat-badge {
  position: absolute;
  top: 8px; right: 8px;
  background: #c83a3a;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  z-index: 6;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 8px rgba(200, 58, 58, 0.55);
  font-variant-numeric: tabular-nums;
}
