.table-chat-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 0.42rem 0.85rem;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.82);
  font: 500 0.78rem/1 'Inter', sans-serif;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.table-chat-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(var(--accent-primary-rgb), 0.35);
  color: rgba(255, 255, 255, 0.96);
}

.table-chat-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.table-chat-unread {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
}

.table-chat-unread.hidden {
  display: none !important;
}

.table-chat-backdrop {
  position: fixed;
  inset: 0;
  /* Above mobile sheet overlays (12000) and GM-edit notice (13000). */
  z-index: 16000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(4px);
}

.table-chat-backdrop.hidden {
  display: none !important;
}

.table-chat-panel {
  display: flex;
  flex-direction: column;
  width: min(480px, calc(100vw - 1.5rem));
  max-height: min(640px, calc(100vh - 2rem));
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #17171f;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.table-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.table-chat-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  letter-spacing: 0.04em;
}

.table-chat-close {
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.72);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.table-chat-close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.table-chat-recipient-row {
  padding: 0.65rem 1rem 0;
}

.table-chat-recipient-row.hidden {
  display: none !important;
}

.table-chat-recipient-label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--text-tertiary);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.table-chat-recipient-select {
  width: 100%;
}

.table-chat-messages {
  flex: 1;
  min-height: 220px;
  max-height: min(420px, 52vh);
  overflow: auto;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.table-chat-empty {
  margin: auto 0;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.88rem;
  line-height: 1.45;
}

.table-chat-empty--broadcast {
  max-width: 34ch;
  margin-inline: auto;
  padding: 0.5rem 0.25rem;
}

.table-chat-error--success {
  color: #86efac !important;
}

.table-chat-message {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: 92%;
}

.table-chat-message--gm {
  align-self: flex-end;
  align-items: flex-end;
}

.table-chat-message--player {
  align-self: flex-start;
  align-items: flex-start;
}

.table-chat-message-meta {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  color: var(--text-tertiary);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
}

.table-chat-message-bubble {
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  line-height: 1.45;
  font-size: 0.92rem;
  word-break: break-word;
}

.table-chat-message--gm .table-chat-message-bubble {
  background: rgba(var(--accent-primary-rgb), 0.22);
  border: 1px solid rgba(var(--accent-primary-rgb), 0.28);
  color: #eef2ff;
}

.table-chat-message--player .table-chat-message-bubble {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(244, 244, 245, 0.96);
}

.table-chat-compose {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.table-chat-input {
  width: 100%;
  min-height: 2.65rem;
  resize: vertical;
}

.table-chat-compose-actions {
  display: flex;
  justify-content: flex-end;
}

.table-chat-error {
  margin: 0;
  padding: 0 1rem 0.75rem;
  color: #fca5a5;
  font-size: 0.82rem;
}

.table-chat-error.hidden {
  display: none !important;
}

@media (max-width: 959px) {
  .table-chat-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .table-chat-panel {
    width: 100%;
    max-height: min(88vh, 720px);
    border-radius: 18px 18px 0 0;
  }

  .table-chat-messages {
    max-height: min(50vh, 420px);
  }
}
