/* Chat Bottom Bar */
.chat-bottom-bar {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 9980;
}

/* Chat Tab (minimized chat) */
.chat-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  background: linear-gradient(135deg, rgba(30, 58, 138, 0.95), rgba(59, 130, 246, 0.9));
  border-radius: 999px;
  color: #f1f5f9;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(148, 163, 184, 0.3);
  cursor: pointer;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}

.chat-tab:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.chat-tab.online {
  border-color: rgba(34, 197, 94, 0.5);
  box-shadow: 0 4px 16px rgba(34, 197, 94, 0.3);
}

.chat-tab-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #3b82f6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 12px;
  overflow: hidden;
  flex-shrink: 0;
}

.chat-tab-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-tab-name {
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-tab-close {
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  margin-left: 4px;
  transition: background 0.2s, color 0.2s;
}

.chat-tab-close:hover {
  background: rgba(239, 68, 68, 0.8);
  color: white;
}

/* Unread badge on chat tab */
.chat-tab-unread {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse 2s infinite;
}

.chat-tab.has-unread {
  animation: shake 0.5s ease-in-out;
}

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

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

/* Contacts Float Button */
.contacts-float-btn {
  padding: 10px 16px;
  background: linear-gradient(135deg, rgba(30, 58, 138, 0.9), rgba(59, 130, 246, 0.85));
  border-radius: 999px;
  color: #f1f5f9;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  cursor: pointer;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}

.contacts-float-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.contacts-float-btn .contact-icon {
  font-size: 18px;
}

.contacts-float-btn .contact-label {
  display: inline;
}

.contacts-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: #ef4444;
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.5);
  margin-left: 4px;
}

.connection-dot.online {
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
}

/* Contacts Dropdown */
.contacts-dropdown {
  position: fixed;
  bottom: 70px;
  right: 16px;
  width: 280px;
  max-height: 400px;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 10000;
  overflow: hidden;
  backdrop-filter: blur(12px);
  animation: slideUp 0.2s ease-out;
}

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

.contacts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  font-weight: 600;
  font-size: 15px;
  color: #f1f5f9;
}

.contacts-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: background 0.2s;
}

.contacts-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.contacts-list {
  max-height: 340px;
  overflow-y: auto;
  padding: 8px;
}

.contacts-empty {
  padding: 30px 16px;
  text-align: center;
  color: rgba(148, 163, 184, 0.7);
  font-size: 13px;
}

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

.contact-item:hover {
  background: rgba(59, 130, 246, 0.15);
}

.contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #3b82f6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 16px;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.contact-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.contact-avatar.online::after {
  content: "";
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 12px;
  height: 12px;
  background: #22c55e;
  border: 2px solid rgba(15, 23, 42, 0.98);
  border-radius: 50%;
}

.contact-name {
  flex: 1;
  font-weight: 500;
  font-size: 14px;
  color: #e2e8f0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.online-badge {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}

/* Unread badge in contacts list */
.contact-unread-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: #ef4444;
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.contact-item.has-unread {
  background: rgba(239, 68, 68, 0.1);
}

.contact-item.has-unread .contact-name {
  font-weight: 600;
  color: #f1f5f9;
}

/* Chat Windows Container */
.chat-windows-container {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  top: 0;
  z-index: 9990;
  pointer-events: none;
}

.chat-window-wrapper {
  position: fixed;
  bottom: 0;
  pointer-events: auto;
  z-index: 9990;
}

/* Light theme */
body[data-theme="light"] .chat-tab {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.95), rgba(99, 102, 241, 0.9));
}

body[data-theme="light"] .contacts-float-btn {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.95), rgba(99, 102, 241, 0.9));
}

body[data-theme="light"] .contacts-dropdown {
  background: rgba(255, 255, 255, 0.98);
  border-color: rgba(148, 163, 184, 0.4);
}

body[data-theme="light"] .contacts-header {
  color: #1e293b;
  border-color: rgba(148, 163, 184, 0.3);
}

body[data-theme="light"] .contact-item:hover {
  background: rgba(59, 130, 246, 0.1);
}

body[data-theme="light"] .contact-name {
  color: #334155;
}

body[data-theme="light"] .contacts-empty {
  color: #64748b;
}

/* Mobile responsive */
@media (max-width: 640px) {
  .chat-bottom-bar {
    right: 8px;
    left: auto;
    gap: 6px;
    bottom: 12px;
  }

  .chat-tab {
    padding: 5px 8px 5px 5px;
  }

  .chat-tab-name {
    max-width: 60px;
    font-size: 12px;
  }

  .chat-tab-avatar {
    width: 24px;
    height: 24px;
    font-size: 10px;
  }

  .contacts-float-btn .contact-label {
    display: none;
  }

  .contacts-float-btn {
    padding: 12px;
  }

  .contacts-dropdown {
    right: 8px;
    left: auto;
    width: 260px;
    bottom: 70px;
  }

  .chat-windows-container {
    left: 0;
    right: 0;
  }

  .chat-window-wrapper {
    left: 0 !important;
    right: 0 !important;
    width: 100%;
    /* Smooth transition for keyboard adjustment */
    transition: bottom 0.15s ease-out;
  }

  /* Hide bottom bar when chat is open to avoid z-index conflicts */
  .chat-windows-container:has(.chat-window:not(.chat-window--minimized)) ~ .chat-bottom-bar {
    z-index: 9980;
  }
}
