/* ============================================================
   CHAT SYSTEM — Facebook-style Chat (Game-themed)
   ============================================================ */

/* ── Chat Toggle Button (top-right, next to settings gear) ─────── */
.chat-toggle-btn {
  position: fixed;
  top: 14px;
  right: 64px;
  z-index: 9999;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(30,41,59,.9), rgba(15,23,42,.95));
  border: 1px solid rgba(255,255,255,.15);
  color: #cbd5e1;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,.6);
  transition: all .2s;
}
.chat-toggle-btn:hover {
  transform: scale(1.1);
  border-color: rgba(165,180,252,.5);
  color: #a5b4fc;
  box-shadow: 0 4px 20px rgba(99, 102, 241, .4);
}
.chat-toggle-btn .chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid #080810;
}

/* ── Sidebar Panel ──────────────────────────────────────────── */
.chat-sidebar {
  position: fixed;
  top: 0;
  right: -360px;
  width: 350px;
  max-width: 90vw;
  height: 100vh;
  z-index: 10000;
  background: linear-gradient(180deg, #0f0b2e 0%, #080818 100%);
  border-left: 1px solid #2d1f6e66;
  box-shadow: -4px 0 30px rgba(0, 0, 0, .5);
  display: flex;
  flex-direction: column;
  transition: right .3s cubic-bezier(.4, 0, .2, 1);
}
.chat-sidebar.open {
  right: 0;
}
.chat-sidebar-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, .4);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
.chat-sidebar-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* Sidebar Header */
.chat-sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(180deg, #1a1450 0%, transparent 100%);
  border-bottom: 1px solid #2d1f6e44;
}
.chat-sidebar-header h3 {
  flex: 1;
  margin: 0;
  font-size: 1rem;
  color: #e2e8f0;
  font-weight: 700;
  letter-spacing: .5px;
}
.chat-sidebar-close {
  background: none;
  border: 1px solid #4338ca44;
  color: #a78bfa;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}
.chat-sidebar-close:hover {
  background: #4338ca33;
  border-color: #a78bfa;
}

/* Sidebar Tabs */
.chat-sidebar-tabs {
  display: flex;
  border-bottom: 1px solid #2d1f6e33;
}
.chat-sidebar-tab {
  flex: 1;
  padding: 10px 8px;
  background: none;
  border: none;
  color: #64748b;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all .2s;
  border-bottom: 2px solid transparent;
  position: relative;
}
.chat-sidebar-tab.active {
  color: #a78bfa;
  border-bottom-color: #a78bfa;
}
.chat-sidebar-tab:hover {
  color: #c4b5fd;
  background: #ffffff05;
}
.chat-sidebar-tab .tab-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 24px);
  min-width: 14px;
  height: 14px;
  border-radius: 7px;
  background: #ef4444;
  color: #fff;
  font-size: .55rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* Sidebar Content */
.chat-sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.chat-sidebar-content::-webkit-scrollbar {
  width: 4px;
}
.chat-sidebar-content::-webkit-scrollbar-thumb {
  background: #4338ca44;
  border-radius: 2px;
}

/* Search Input */
.chat-search-box {
  padding: 8px 12px;
}
.chat-search-input {
  width: 100%;
  background: #0f0a2a;
  border: 1px solid #2d1f6e44;
  border-radius: 8px;
  padding: 8px 12px;
  color: #e2e8f0;
  font-size: .85rem;
  outline: none;
  transition: border-color .2s;
}
.chat-search-input::placeholder {
  color: #475569;
}
.chat-search-input:focus {
  border-color: #6366f1;
}

/* User List Items */
.chat-user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background .15s;
}
.chat-user-item:hover {
  background: #ffffff08;
}
.chat-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #312e81, #1e1b4b);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  color: #a78bfa;
  flex-shrink: 0;
  position: relative;
}
.chat-user-status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #0f0b2e;
}
.chat-user-status-dot.online { background: #22c55e; }
.chat-user-status-dot.away   { background: #f59e0b; }
.chat-user-status-dot.offline { background: #475569; }
.chat-user-info {
  flex: 1;
  min-width: 0;
}
.chat-user-name {
  font-size: .85rem;
  color: #e2e8f0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-user-status-text {
  font-size: .65rem;
  color: #64748b;
  margin-top: 1px;
}
.chat-user-status-text.online { color: #22c55e; }
.chat-user-status-text.away   { color: #f59e0b; }
.chat-user-unread-badge {
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: #ef4444;
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* Friend request actions */
.chat-friend-actions {
  display: flex;
  gap: 6px;
}
.chat-friend-accept,
.chat-friend-reject {
  padding: 4px 10px;
  border-radius: 6px;
  border: none;
  font-size: .7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.chat-friend-accept {
  background: #22c55e22;
  color: #22c55e;
  border: 1px solid #22c55e44;
}
.chat-friend-accept:hover {
  background: #22c55e44;
}
.chat-friend-reject {
  background: #ef444422;
  color: #ef4444;
  border: 1px solid #ef444444;
}
.chat-friend-reject:hover {
  background: #ef444444;
}

/* Add friend button within search results */
.chat-add-friend-btn {
  padding: 4px 12px;
  border-radius: 6px;
  background: #6366f122;
  color: #a78bfa;
  border: 1px solid #6366f144;
  font-size: .7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.chat-add-friend-btn:hover {
  background: #6366f144;
}
.chat-add-friend-btn:disabled {
  opacity: .5;
  cursor: default;
}

/* Empty state */
.chat-empty {
  padding: 30px 20px;
  text-align: center;
  color: #475569;
  font-size: .8rem;
}
.chat-empty-icon {
  font-size: 2rem;
  margin-bottom: 8px;
}

/* ── Chat Windows (bottom, Facebook-style) ──────────────────── */
.chat-windows-container {
  position: fixed;
  bottom: 0;
  right: 16px;
  z-index: 9998;
  display: flex;
  flex-direction: row-reverse;
  gap: 8px;
  align-items: flex-end;
  pointer-events: none;
}
.chat-window {
  width: 320px;
  max-width: 85vw;
  height: 380px;
  position: relative;
  background: linear-gradient(180deg, #12102a 0%, #0a0a1a 100%);
  border: 1px solid #2d1f6e55;
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, .4);
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  transition: none;
}
.chat-window.minimized {
  height: 44px !important;
  overflow: hidden;
}

/* Resize Handle (top border) */
.chat-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  cursor: ns-resize;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px 12px 0 0;
  transition: background .15s;
}
.chat-resize-handle:hover,
.chat-resize-handle:active {
  background: rgba(139, 92, 246, .25);
}
.chat-resize-grip {
  width: 36px;
  height: 3px;
  border-radius: 2px;
  background: rgba(139, 92, 246, .35);
  transition: background .15s, width .15s;
}
.chat-resize-handle:hover .chat-resize-grip,
.chat-resize-handle:active .chat-resize-grip {
  background: rgba(139, 92, 246, .7);
  width: 48px;
}

/* Window Header */
.chat-window-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(180deg, #1a1450 0%, #12102a 100%);
  border-radius: 12px 12px 0 0;
  cursor: pointer;
  flex-shrink: 0;
  border-bottom: 1px solid #2d1f6e33;
}
.chat-window-header:hover {
  background: linear-gradient(180deg, #1e1860 0%, #14133a 100%);
}
.chat-window-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #312e81, #1e1b4b);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  color: #a78bfa;
  position: relative;
  flex-shrink: 0;
}
.chat-window-avatar .chat-user-status-dot {
  width: 8px;
  height: 8px;
  border-width: 1.5px;
  border-color: #1a1450;
}
.chat-window-name {
  flex: 1;
  font-size: .82rem;
  color: #e2e8f0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-window-minimize,
.chat-window-close {
  background: none;
  border: none;
  color: #64748b;
  font-size: .9rem;
  cursor: pointer;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all .15s;
}
.chat-window-minimize:hover,
.chat-window-close:hover {
  color: #e2e8f0;
  background: #ffffff11;
}
.chat-window-header .chat-window-unread {
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  background: #ef4444;
  color: #fff;
  font-size: .6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* Messages Area */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 10px 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-messages::-webkit-scrollbar {
  width: 3px;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: #4338ca33;
  border-radius: 2px;
}

/* Load more */
.chat-load-more {
  text-align: center;
  padding: 6px;
}
.chat-load-more button {
  background: none;
  border: 1px solid #4338ca33;
  color: #64748b;
  font-size: .7rem;
  cursor: pointer;
  padding: 3px 10px;
  border-radius: 4px;
}
.chat-load-more button:hover {
  color: #a78bfa;
  border-color: #6366f1;
}

/* Message Bubbles */
.chat-msg {
  max-width: 80%;
  padding: 7px 11px;
  border-radius: 14px;
  font-size: .8rem;
  line-height: 1.35;
  word-wrap: break-word;
}
.chat-msg.sent {
  align-self: flex-end;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.received {
  align-self: flex-start;
  background: #1e1b4b;
  color: #e2e8f0;
  border-bottom-left-radius: 4px;
}
.chat-msg-time {
  font-size: .55rem;
  color: rgba(255, 255, 255, .4);
  margin-top: 2px;
  text-align: right;
}
.chat-msg.received .chat-msg-time {
  text-align: left;
  color: #475569;
}

/* Day separator */
.chat-day-sep {
  text-align: center;
  font-size: .6rem;
  color: #475569;
  padding: 6px 0;
}

/* Input Area */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid #2d1f6e22;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  background: #0f0a2a;
  border: 1px solid #2d1f6e33;
  border-radius: 18px;
  padding: 7px 14px;
  color: #e2e8f0;
  font-size: .8rem;
  outline: none;
  transition: border-color .2s;
}
.chat-input::placeholder {
  color: #475569;
}
.chat-input:focus {
  border-color: #6366f1;
}
.chat-send-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  color: #fff;
  font-size: .85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
  flex-shrink: 0;
}
.chat-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(99, 102, 241, .4);
}
.chat-send-btn:disabled {
  opacity: .4;
  cursor: default;
  transform: none;
}

/* ── Minimized Windows Bar ──────────────────────────────────── */
.chat-minimized-bar {
  position: fixed;
  bottom: 0;
  right: 70px;
  z-index: 9997;
  display: flex;
  flex-direction: row-reverse;
  gap: 6px;
  align-items: flex-end;
}
.chat-minimized-bubble {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #312e81, #1e1b4b);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  color: #a78bfa;
  cursor: pointer;
  position: relative;
  border: 2px solid #4338ca44;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
  margin-bottom: 8px;
  transition: all .15s;
}
.chat-minimized-bubble:hover {
  transform: scale(1.1);
  border-color: #a78bfa;
}
.chat-minimized-bubble .mini-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  background: #ef4444;
  color: #fff;
  font-size: .55rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  border: 2px solid #080810;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Sidebar: must use -100vw so the full 100vw-wide panel hides completely */
  .chat-sidebar {
    width: 100vw;
    max-width: 100vw;
    right: -100vw; /* was -360px which left ~30px visible on phones */
  }
  /* Floating chat windows are too wide for phones — hide them;
     users can reopen from the minimized bar or sidebar instead */
  .chat-windows-container {
    display: none;
  }
  .chat-minimized-bar {
    display: none;
  }
  .chat-toggle-btn {
    width: 34px;
    height: 34px;
    font-size: .95rem;
    top: 50px;
    right: 10px;
  }
}

/* ═══════════════════════════════════════════════════════════════
   Context Menu (right-click)
   ═══════════════════════════════════════════════════════════════ */
.chat-ctx-menu {
  position: fixed;
  z-index: 100000;
  min-width: 200px;
  background: #1e1b2e;
  border: 1px solid rgba(139, 92, 246, .45);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.55);
  padding: 6px 0;
  animation: ctxFadeIn .12s ease;
}
@keyframes ctxFadeIn {
  from { opacity: 0; transform: scale(.95); }
  to   { opacity: 1; transform: scale(1); }
}
.chat-ctx-item {
  padding: 9px 16px;
  font-size: .82rem;
  color: #e2e0f0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background .15s;
}
.chat-ctx-item:hover {
  background: rgba(139, 92, 246, .2);
}
.chat-ctx-item.danger {
  color: #f87171;
}
.chat-ctx-item.danger:hover {
  background: rgba(248, 113, 113, .15);
}

/* ═══════════════════════════════════════════════════════════════
   Challenge Notification Overlay
   ═══════════════════════════════════════════════════════════════ */
.chat-challenge-overlay {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100001;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.chat-challenge-banner {
  pointer-events: auto;
  background: linear-gradient(135deg, #1e1b2e 0%, #2d1a4e 100%);
  border: 1.5px solid rgba(139, 92, 246, .6);
  border-radius: 12px;
  padding: 16px 24px;
  box-shadow: 0 8px 32px rgba(139, 92, 246, .25), 0 4px 16px rgba(0,0,0,.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 300px;
  animation: challengeSlideIn .3s ease;
}
@keyframes challengeSlideIn {
  from { opacity: 0; transform: translateY(-20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-challenge-text {
  font-size: .95rem;
  color: #e2e0f0;
  text-align: center;
}
.chat-challenge-text strong {
  color: #a78bfa;
}
.chat-challenge-actions {
  display: flex;
  gap: 12px;
}
.chat-challenge-accept,
.chat-challenge-reject {
  padding: 8px 20px;
  border: none;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s, transform .1s;
}
.chat-challenge-accept {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: #fff;
}
.chat-challenge-accept:hover {
  filter: brightness(1.15);
  transform: scale(1.04);
}
.chat-challenge-reject {
  background: rgba(255,255,255,.08);
  color: #a0a0b8;
  border: 1px solid rgba(255,255,255,.12);
}
.chat-challenge-reject:hover {
  background: rgba(248, 113, 113, .15);
  color: #f87171;
}

/* ═══════════════════════════════════════════════════════════════
   In-Game Popup (replaces browser alert/confirm)
   ═══════════════════════════════════════════════════════════════ */
.game-popup-overlay {
  position: fixed;
  inset: 0;
  z-index: 200000;
  background: rgba(0, 0, 0, .65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: popupOverlayIn .2s ease;
}
@keyframes popupOverlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.game-popup {
  background: linear-gradient(145deg, #1a1730 0%, #261e45 50%, #1a1730 100%);
  border: 1.5px solid rgba(139, 92, 246, .5);
  border-radius: 16px;
  padding: 32px 36px 28px;
  min-width: 320px;
  max-width: 420px;
  box-shadow:
    0 0 40px rgba(139, 92, 246, .2),
    0 16px 48px rgba(0, 0, 0, .6),
    inset 0 1px 0 rgba(255, 255, 255, .06);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: popupSlideIn .25s ease;
  text-align: center;
}
@keyframes popupSlideIn {
  from { opacity: 0; transform: scale(.9) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.game-popup-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
}
.game-popup-icon.success {
  background: linear-gradient(135deg, rgba(34,197,94,.2), rgba(34,197,94,.1));
  border: 2px solid rgba(34, 197, 94, .5);
  color: #22c55e;
  box-shadow: 0 0 20px rgba(34, 197, 94, .15);
}
.game-popup-icon.error {
  background: linear-gradient(135deg, rgba(239,68,68,.2), rgba(239,68,68,.1));
  border: 2px solid rgba(239, 68, 68, .5);
  color: #ef4444;
  box-shadow: 0 0 20px rgba(239, 68, 68, .15);
}
.game-popup-icon.confirm {
  background: linear-gradient(135deg, rgba(139,92,246,.2), rgba(139,92,246,.1));
  border: 2px solid rgba(139, 92, 246, .5);
  color: #a78bfa;
  box-shadow: 0 0 20px rgba(139, 92, 246, .15);
}
.game-popup-icon.info {
  background: linear-gradient(135deg, rgba(59,130,246,.2), rgba(59,130,246,.1));
  border: 2px solid rgba(59, 130, 246, .5);
  color: #3b82f6;
  box-shadow: 0 0 20px rgba(59, 130, 246, .15);
}
.game-popup-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #f0ecff;
  letter-spacing: .3px;
}
.game-popup-message {
  font-size: .88rem;
  color: #b8b0d4;
  line-height: 1.5;
  max-width: 340px;
}
.game-popup-buttons {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}
.game-popup-btn {
  padding: 10px 28px;
  border: none;
  border-radius: 10px;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
  letter-spacing: .3px;
}
.game-popup-btn.confirm {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: #fff;
  box-shadow: 0 4px 16px rgba(124, 58, 237, .3);
}
.game-popup-btn.confirm:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(124, 58, 237, .4);
}
.game-popup-btn.cancel {
  background: rgba(255, 255, 255, .06);
  color: #a0a0b8;
  border: 1px solid rgba(255, 255, 255, .1);
}
.game-popup-btn.cancel:hover {
  background: rgba(255, 255, 255, .1);
  color: #e2e0f0;
}
