/* ── Persistent Chat Panel ────────────────────────────── */
/* Floating Discord-style panel, lives outside all .screen
   divs so it survives navigation. */

.chat-panel {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 360px;
  height: 520px;
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  z-index: 9999;
  overflow: hidden;
  font-size: 14px;
  color: var(--text);
}

.chat-panel.hidden {
  display: none;
}

/* ── Header ──────────────────────────────────────────── */

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  min-height: 42px;
  cursor: default;
  user-select: none;
}

.chat-panel-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-panel-back {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 6px;
  margin-right: 6px;
  font-size: 16px;
  line-height: 1;
  border-radius: 4px;
}

.chat-panel-back:hover {
  color: var(--text);
  background: var(--surface);
}

.chat-panel-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-panel-actions button {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
}

.chat-panel-actions button:hover {
  color: var(--text);
  background: var(--surface);
}

/* ── Body (channel list + conversation) ──────────────── */

.chat-panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ── Channel List ────────────────────────────────────── */

.chat-panel-channels {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.chat-channel-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.1s;
}

.chat-channel-item:hover {
  background: var(--surface2);
}

.chat-channel-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface2);
  flex-shrink: 0;
  object-fit: cover;
}

.chat-channel-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-channel-name {
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-channel-preview {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-channel-unread {
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
  box-sizing: border-box;
}

.chat-channel-call-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  opacity: 0.4;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.chat-channel-call-btn:hover {
  opacity: 1;
}

.chat-channel-presence {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 5px;
}

.chat-presence-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  opacity: 0.4;
}

.chat-presence-dot.online {
  background: #48bb78;
  opacity: 1;
}

.chat-channel-offline {
  opacity: 0.65;
}

.chat-channels-empty {
  padding: 32px 14px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.chat-start-dm-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  margin-top: 8px;
  font-family: inherit;
}

.chat-start-dm-link:hover {
  text-decoration: underline;
}

/* ── New DM Button ───────────────────────────────────── */

.chat-new-dm-btn {
  background: var(--accent) !important;
  color: #fff !important;
  width: 26px !important;
  height: 26px !important;
  border-radius: 50% !important;
  font-size: 16px !important;
  font-weight: 600;
  line-height: 1;
  display: flex !important;
  align-items: center;
  justify-content: center;
}

.chat-new-dm-btn:hover {
  opacity: 0.85;
}

/* ── Friend Picker ───────────────────────────────────── */

.chat-friend-search {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  font-family: inherit;
}

.chat-friend-search::placeholder {
  color: var(--text-dim);
}

.chat-friend-search:focus {
  border-color: var(--accent);
}

.chat-friend-picker {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.chat-friend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.1s;
}

.chat-friend-item:hover {
  background: var(--surface2);
}

.chat-avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
}

.chat-friend-online-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #48bb78;
  margin-left: 5px;
  vertical-align: middle;
}

/* ── Conversation View ───────────────────────────────── */

.chat-panel-conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-panel-conversation.hidden {
  display: none;
}

.chat-panel-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-panel .chat-msg {
  max-width: 85%;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: none;
  opacity: 1;
  backdrop-filter: none;
}

.chat-msg-mine {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 3px;
}

.chat-msg-theirs {
  align-self: flex-start;
  background: var(--surface2);
  color: var(--text);
  border-bottom-left-radius: 3px;
}

.chat-msg-time {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
  padding: 0 2px;
}

.chat-system-notice {
  text-align: center;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  margin: 4px 0;
}

.chat-notice-error {
  color: #e53e3e;
  background: rgba(229, 62, 62, 0.1);
}

.chat-notice-warn {
  color: var(--accent);
  background: rgba(var(--accent-rgb, 0, 229, 160), 0.1);
}

.chat-msg-time-right {
  text-align: right;
}

.chat-typing-indicator {
  padding: 2px 14px 6px;
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  min-height: 20px;
}

/* ── Input Row ───────────────────────────────────────── */

.chat-panel-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-panel-input-row input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  font-family: inherit;
}

.chat-panel-input-row input::placeholder {
  color: var(--text-dim);
}

.chat-panel-input-row input:focus {
  border-color: var(--accent);
}

.chat-panel-send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
  transition: opacity 0.1s;
}

.chat-panel-send-btn:hover {
  opacity: 0.85;
}

.chat-panel-send-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── Voice Call Controls ─────────────────────────────── */

.chat-voice-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.chat-voice-btn:hover {
  color: var(--text);
  background: var(--surface);
}

.chat-call-btn {
  color: var(--accent);
}

.chat-call-btn:hover {
  color: #fff;
  background: var(--accent);
}

.chat-hangup-btn {
  color: #e53e3e;
}

.chat-hangup-btn:hover {
  color: #fff;
  background: #e53e3e;
}

.chat-accept-btn {
  color: #4caf50;
}

.chat-accept-btn:hover {
  color: #fff;
  background: #4caf50;
}

.chat-incoming-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  animation: chat-voice-pulse 1.5s ease-in-out infinite;
}

.chat-calling-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.chat-voice-btn.mic-active {
  filter: drop-shadow(0 0 calc(var(--mic-level, 0) * 8px) var(--accent));
  color: var(--accent);
  transition: filter 0.05s;
}

.chat-voice-active-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 5px;
  vertical-align: middle;
  animation: chat-voice-pulse 1.5s ease-in-out infinite;
}

@keyframes chat-voice-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.chat-listening-badge {
  font-size: 11px;
  color: var(--accent);
  padding: 2px 8px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  white-space: nowrap;
  opacity: 0.8;
}

/* ── Load More ───────────────────────────────────────── */

.chat-load-more {
  text-align: center;
  padding: 6px;
}

.chat-load-more button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
}

.chat-load-more button:hover {
  text-decoration: underline;
}

/* ── FAB (Floating Action Button) ────────────────────── */

.chat-panel-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s, box-shadow 0.15s, bottom 0.2s ease;
}

.chat-panel-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.chat-panel-fab.hidden {
  display: none;
}

.chat-panel-fab.incoming-call {
  animation: fab-pulse 1s ease-in-out infinite;
}

@keyframes fab-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3); }
  50% { transform: scale(1.15); box-shadow: 0 0 20px var(--accent); }
}

.chat-panel-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #e53e3e;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}

.chat-panel-badge.hidden {
  display: none;
}

/* ── Scrollbar styling ───────────────────────────────── */

.chat-panel-messages::-webkit-scrollbar,
.chat-panel-channels::-webkit-scrollbar {
  width: 5px;
}

.chat-panel-messages::-webkit-scrollbar-thumb,
.chat-panel-channels::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ── Mobile ──────────────────────────────────────────── */

@media (max-width: 600px) {
  .chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 70vh;
    border-radius: 12px 12px 0 0;
  }

  .chat-panel-fab {
    bottom: 12px;
    right: 12px;
    width: 46px;
    height: 46px;
    font-size: 20px;
  }
}

body:has(.touch-gamepad:not(.hidden)) .chat-panel-fab {
  bottom: max(220px, calc(env(safe-area-inset-bottom) + 210px));
}
