/* ═══════════════════════════════════════════════════════════
   ADAPTIVE CHAT DOCK — CSS (Social V3 Phase 3.5)
   Desktop: Fixed dock tại bottom-right + Mini Chat windows
   Mobile: FAB tròn → Bottom Sheet 80vh + Fullscreen Chat
   ═══════════════════════════════════════════════════════════ */

/* [v9.19] Màu accent đồng bộ với màu chủ đề trong Cài Đặt */
:root {
  --chat-accent:      #d32f2f;
  --chat-accent-dark: #b71c1c;
  --chat-accent-rgb:  211, 47, 47;
}
body[data-theme="academy"] { --chat-accent: #0277bd; --chat-accent-dark: #01579b; --chat-accent-rgb: 2, 119, 189; }
body[data-theme="rose"]    { --chat-accent: #e91e63; --chat-accent-dark: #c2185b; --chat-accent-rgb: 233, 30, 99; }
body[data-theme="forest"]  { --chat-accent: #2e7d32; --chat-accent-dark: #1b5e20; --chat-accent-rgb: 46, 125, 50; }
body[data-theme="gold"]    { --chat-accent: #f57f17; --chat-accent-dark: #e65100; --chat-accent-rgb: 245, 127, 23; }
body[data-theme="ocean"]   { --chat-accent: #00838f; --chat-accent-dark: #006064; --chat-accent-rgb: 0, 131, 143; }

/* ── DOCK CONTAINER (Bọc ngoài) ── */
#adaptive-chat-dock {
  position: fixed;
  bottom: 0;
  right: 20px;
  z-index: 9990;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}

#adaptive-chat-dock > * {
  pointer-events: auto;
}

/* ── MASTER TAB (Desktop) ── */
.dock-master-tab {
  width: 320px;
  background: #1a1a22;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.35);
  overflow: hidden;
  transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid #2a2a34;
  border-bottom: none;
}

.dock-master-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-dark));
  cursor: pointer;
  user-select: none;
}

.dock-master-header:hover {
  filter: brightness(1.1);
}

.dock-master-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dock-master-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.3);
}

.dock-master-name {
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dock-master-toggle {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
  transition: transform 0.3s ease;
}

.dock-master-toggle.expanded {
  transform: rotate(180deg);
}

/* ── TAB BAR ── */
.dock-tab-bar {
  display: flex;
  border-bottom: 1px solid #2a2a34;
  background: #15151c;
}

.dock-tab {
  flex: 1;
  padding: 8px 6px;
  background: none;
  border: none;
  color: #777;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.2s, border-bottom 0.2s;
  border-bottom: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.dock-tab:hover {
  color: #bbb;
}

.dock-tab.active {
  color: var(--chat-accent);
  border-bottom: 2px solid var(--chat-accent);
}

.dock-req-count {
  background: #e91e63;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 8px;
  padding: 0 4px;
  animation: dockBadgePulse 2s infinite;
}

/* ── FRIEND LIST BODY ── */
.dock-body {
  max-height: 0;
  overflow-y: auto;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: #141418;
}

.dock-body.expanded {
  max-height: 380px;
}

.dock-body::-webkit-scrollbar {
  width: 4px;
}
.dock-body::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 2px;
}

.dock-tab-content {
  padding: 4px;
  min-height: 100px;
}

.dock-friend-list-inner {
  padding: 4px;
}

.dock-friend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.dock-friend-item:hover {
  background: rgba(255,255,255,0.06);
}

/* ── Avatar Wrap + Presence Dot ── */
.dock-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.dock-friend-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #333;
}

.dock-presence-dot {
  display: none;
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
  border: 2px solid #1a1a22;
}

.dock-presence-dot.online {
  display: block;
}

.dock-friend-name {
  color: #ccc;
  font-size: 0.85rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dock-friend-uid {
  color: #666;
  font-size: 0.72rem;
  margin-top: 1px;
}

.dock-empty-msg {
  text-align: center;
  padding: 25px 15px;
  color: #666;
  font-size: 0.85rem;
}

.dock-empty-msg i {
  display: block;
  font-size: 2rem;
  margin-bottom: 10px;
  opacity: 0.4;
}

/* ── REQUEST LIST ── */
.dock-request-list {
  padding: 4px;
}

.dock-request-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  transition: background 0.2s;
}

.dock-request-item:hover {
  background: rgba(255,255,255,0.04);
}

.dock-request-info {
  flex: 1;
  min-width: 0;
}

.dock-request-actions {
  display: flex;
  gap: 6px;
  margin-top: 5px;
}

.dock-btn-accept {
  background: linear-gradient(135deg, #4caf50, #388e3c);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.75rem;
  transition: transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dock-btn-accept:hover { transform: scale(1.15); }
.dock-btn-accept:disabled { opacity: 0.5; cursor: not-allowed; }

.dock-btn-decline {
  background: linear-gradient(135deg, #616161, #424242);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.75rem;
  transition: transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dock-btn-decline:hover { transform: scale(1.15); }
.dock-btn-decline:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── FRIEND REQUEST BADGE ── */
.dock-badge {
  background: #e91e63;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 9px;
  padding: 0 5px;
  position: absolute;
  top: -4px;
  right: -4px;
  box-shadow: 0 2px 6px rgba(233,30,99,0.5);
  animation: dockBadgePulse 2s infinite;
}

@keyframes dockBadgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* ── FAB BUTTON (hiện cả desktop lẫn mobile) ── */
.dock-fab {
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-dark));
  color: #fff;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  z-index: 9990;
  box-shadow: 0 4px 16px rgba(var(--chat-accent-rgb), 0.4);
  transition: transform 0.2s, box-shadow 0.2s, background 0.3s;
}

/* Desktop: snap animation khi thả bubble */
@media (min-width: 768px) {
  .dock-fab {
    transition: left 0.3s cubic-bezier(0.25, 0.8, 0.25, 1),
                top 0.3s cubic-bezier(0.25, 0.8, 0.25, 1),
                transform 0.2s, box-shadow 0.2s;
  }
}

.dock-fab.is-dragging {
  transition: none !important;
  transform: scale(1.05) !important;
  cursor: grabbing !important;
  box-shadow: 0 8px 32px rgba(var(--chat-accent-rgb), 0.5) !important;
}

.dock-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(var(--chat-accent-rgb), 0.5);
}

.dock-fab:active {
  transform: scale(0.95);
}

/* ── MOBILE: FULLSCREEN DOCK (giống Notification Panel) ── */
.dock-bottom-sheet-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99999;
  backdrop-filter: blur(3px);
}

.dock-bottom-sheet-overlay.active {
  display: block;
}

.dock-bottom-sheet {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh; /* Dynamic VH — tránh nháy khi address bar thu/mở */
  background: #121218;
  z-index: 100000;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.25, 0.8, 0.25, 1);
  overflow-y: auto;
  overscroll-behavior: contain; /* Không lan scroll ra trang chính */
  display: flex;
  flex-direction: column;
  border-radius: 0;
  pointer-events: none;
}

.dock-bottom-sheet.active {
  transform: translateX(0);
  pointer-events: auto;
}

.dock-bottom-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(135deg, #1a1a24, #0d0d12);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
  min-height: 56px;
}

.dock-bottom-sheet-header h4 {
  color: #fff;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dock-bottom-sheet-close {
  background: rgba(229, 57, 53, 0.15);
  border: none;
  color: #e53935;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 6px 14px;
  border-radius: 20px;
  transition: all 0.2s;
  font-weight: 600;
}

.dock-bottom-sheet-close:hover {
  background: rgba(229, 57, 53, 0.3);
  color: #fff;
}

.dock-bottom-sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 8px;
  padding-bottom: 80px;
}

.dock-grab-handle {
  display: none; /* Ẩn trên fullscreen */
}

/* ── RESPONSIVE SWITCHOVER ── */
@media (max-width: 767px) {
  #adaptive-chat-dock {
    display: none !important;
  }
  .dock-fab {
    display: flex !important;
    align-items: center;
    justify-content: center;
  }
  /* [U4] Mobile: Mini Chat fullscreen slide-in, z-index > Dock */
  .dock-mini-chat {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100vh !important;
    height: 100dvh !important; /* Dynamic VH — tránh nháy khi address bar thu/mở */
    border-radius: 0 !important;
    z-index: 100001 !important;
    animation: none !important; /* Tắt slide-up trên mobile, dùng opacity */
    overscroll-behavior: contain !important;
    touch-action: pan-y !important;
  }

  .dock-mini-chat .dock-chat-body {
    overscroll-behavior: contain; /* Chat body scroll không lan ra ngoài */
    -webkit-overflow-scrolling: touch;
  }
}

/* Khoá scroll trang chính khi mở fullscreen panel trên mobile */
body.dock-chat-open {
  overflow: hidden !important;
  position: fixed !important;
  width: 100% !important;
  touch-action: none !important;
}

@media (min-width: 768px) {
  /* Bubble (dock-fab) HIỆN trên desktop — draggable tự do */
  /* Dock panel ẩn mặc định — FAB click JS sẽ toggle hiện/ẩn */
  #adaptive-chat-dock {
    display: none;
  }
  .dock-bottom-sheet-overlay,
  .dock-bottom-sheet {
    display: none !important;
  }
}

/* ═══════════════════════════════════════════════════════════
   [PHASE 3] MINI CHAT WINDOW
   ═══════════════════════════════════════════════════════════ */

.dock-mini-chat {
  position: fixed;
  bottom: 0;
  right: 350px;
  width: 320px;
  height: 400px;
  background: #1a1a22;
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.4);
  border: 1px solid #2a2a34;
  border-bottom: none;
  z-index: 9991;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: dockChatSlideUp 0.3s ease-out;
}

.dock-mini-chat:nth-of-type(2) { right: 680px; }
.dock-mini-chat:nth-of-type(3) { right: 1010px; }

@keyframes dockChatSlideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Chat Header ── */
.dock-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: linear-gradient(135deg, #2a2a34, #1f1f28);
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}

.dock-chat-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.dock-chat-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #444;
  flex-shrink: 0;
}

.dock-chat-name {
  color: #ddd;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dock-chat-close {
  background: none;
  border: none;
  color: #888;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 2px 5px;
  transition: color 0.2s;
  flex-shrink: 0;
}

.dock-chat-close:hover {
  color: #e91e63;
}

/* ── Chat Body ── */
.dock-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  background: #111116;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dock-chat-body::-webkit-scrollbar {
  width: 3px;
}
.dock-chat-body::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 2px;
}

/* ── Message Bubbles ── */
.dock-chat-msg {
  max-width: 80%;
  padding: 7px 11px;
  border-radius: 12px;
  font-size: 0.83rem;
  line-height: 1.4;
  word-break: break-word;
  display: flex;
  flex-direction: column;
  animation: dockMsgFade 0.2s ease;
}

@keyframes dockMsgFade {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dock-chat-msg.me {
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-dark));
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.dock-chat-msg.them {
  background: #2a2a34;
  color: #ddd;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.dock-chat-msg-text {
  display: block;
}

.dock-chat-msg-time {
  font-size: 0.65rem;
  opacity: 0.6;
  margin-top: 3px;
  align-self: flex-end;
}

/* ── Chat Footer ── */
.dock-chat-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: #1a1a22;
  border-top: 1px solid #333;
  flex-shrink: 0;
}

.dock-chat-input {
  flex: 1;
  background: #111116;
  border: 1px solid #333;
  border-radius: 18px;
  padding: 7px 14px;
  color: #ddd;
  font-size: 0.83rem;
  outline: none;
  transition: border-color 0.2s;
}

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

.dock-chat-input::placeholder {
  color: #555;
}

.dock-chat-send {
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-dark));
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: transform 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}

.dock-chat-send:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(var(--chat-accent-rgb), 0.4);
}

.dock-chat-send:active {
  transform: scale(0.95);
}

/* -- Sprint 3.7: Unread Badge System -- */
.dock-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 10px;
  background: linear-gradient(135deg, #f44336, #e91e63);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  margin-left: 6px;
  box-shadow: 0 2px 6px rgba(244,67,54,0.4);
  animation: dock-badge-pop 0.3s ease;
}
@keyframes dock-badge-pop {
  from { transform: scale(0); }
  to { transform: scale(1); }
}
.dock-unread-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f44336;
  box-shadow: 0 0 4px rgba(244,67,54,0.6);
}
.dock-friend-item {
  position: relative;
}
.dock-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 10px;
  background: linear-gradient(135deg, #f44336, #e91e63);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(244,67,54,0.5);
  animation: dock-badge-pop 0.3s ease;
}

/* ═══════════════════════════════════════════════════════════
   [v9.19] TOÀN MÔN — Server Group Chat (inline trong dock body)
   ═══════════════════════════════════════════════════════════ */
.dock-server-wrap {
  display: flex;
  flex-direction: column;
  height: 330px;
}

.dock-server-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dock-server-msgs::-webkit-scrollbar { width: 3px; }
.dock-server-msgs::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }

.dock-server-msg {
  display: flex;
  align-items: flex-start;
  gap: 7px;
}

.dock-server-msg.me {
  flex-direction: row-reverse;
}

.dock-server-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid #333;
}

.dock-server-bubble-wrap {
  max-width: 70%;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dock-server-msg.me .dock-server-bubble-wrap {
  align-items: flex-end;
}

.dock-server-sender {
  font-size: 0.68rem;
  color: #888;
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.dock-server-text {
  background: #2a2a34;
  color: #ddd;
  padding: 6px 10px;
  border-radius: 10px 10px 10px 2px;
  font-size: 0.8rem;
  line-height: 1.4;
  word-break: break-word;
}

.dock-server-msg.me .dock-server-text {
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-dark));
  color: #fff;
  border-radius: 10px 10px 2px 10px;
}

.dock-server-time {
  font-size: 0.62rem;
  color: #555;
  padding: 0 4px;
}

.dock-server-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-top: 1px solid #2a2a34;
  background: #1a1a22;
  flex-shrink: 0;
}

.dock-server-input {
  flex: 1;
  background: #111116;
  border: 1px solid #333;
  border-radius: 16px;
  padding: 6px 12px;
  color: #ddd;
  font-size: 0.8rem;
  outline: none;
  transition: border-color 0.2s;
}

.dock-server-input:focus { border-color: var(--chat-accent); }
.dock-server-input::placeholder { color: #555; }

.dock-server-send {
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-accent-dark));
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  flex-shrink: 0;
  transition: transform 0.2s;
}

.dock-server-send:hover { transform: scale(1.1); }
.dock-server-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
