/* ─── Sidebar ──────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 12px;
  height: var(--header-height);
  border-bottom: 1px solid var(--border-light);
}

.sidebar-search {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  width: 18px; height: 18px;
  color: var(--text-tertiary);
  pointer-events: none;
  transition: all 0.3s ease;
}

.search-input:focus ~ .search-icon,
.search-input:focus + .search-icon {
  color: var(--primary);
}

.search-input {
  width: 100%;
  padding: 10px 12px 10px 40px;
  background: var(--bg-hover);
  border: 1.5px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: all 0.3s ease;
}

/* ─── Chat Folders ──────────────────────────────────── */
.chat-folders {
  display: flex;
  align-items: center;
  overflow-x: auto;
  padding: 8px 12px !important;
  gap: 8px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-sidebar);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.chat-folders::-webkit-scrollbar {
  display: none;
}

.folder-tab {
  padding: 6px 14px !important;
  border: 1px solid transparent !important;
  background: var(--bg-hover) !important;
  color: var(--text-secondary) !important;
  font-size: 0.82rem !important;
  font-weight: 600 !important;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 10px !important;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
  border-bottom: none !important;
  flex-shrink: 0;
}

.folder-tab:hover {
  background: var(--bg-active) !important;
  color: var(--text-primary) !important;
}

.folder-tab:active {
  transform: scale(0.95);
}

.folder-tab.active {
  background: var(--primary) !important;
  color: #fff !important;
  box-shadow: 0 4px 10px var(--primary-glow) !important;
}

.add-folder-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50% !important;
  background: var(--bg-hover) !important;
  color: var(--primary) !important;
  transition: all 0.2s ease !important;
  margin-left: auto !important;
}

.add-folder-btn:hover {
  background: var(--primary-bg) !important;
  transform: rotate(90deg);
}

  font-size: 0.88rem;
  outline: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.search-input:focus {
  background: var(--bg-input);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-bg);
}

.search-input::placeholder { color: var(--text-tertiary); }

.sidebar-search::after {
  content: 'Ctrl K';
  position: absolute;
  right: 12px;
  font-size: 10px;
  background: var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-tertiary);
  pointer-events: none;
  opacity: 0.6;
  transition: opacity 0.3s;
}

.search-input:focus ~ ::after { opacity: 0; }
@media (max-width: 768px) { .sidebar-search::after { display: none; } }

/* ─── Chat List ────────────────────────────────────── */
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  /* Staggered entrance animation */
  animation: chatItemSlide 0.4s cubic-bezier(0.16, 1, 0.3, 1) backwards;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-item:nth-child(1) { animation-delay: 0.02s; }
.chat-item:nth-child(2) { animation-delay: 0.04s; }
.chat-item:nth-child(3) { animation-delay: 0.06s; }
.chat-item:nth-child(4) { animation-delay: 0.08s; }
.chat-item:nth-child(5) { animation-delay: 0.10s; }
.chat-item:nth-child(6) { animation-delay: 0.12s; }
.chat-item:nth-child(7) { animation-delay: 0.14s; }
.chat-item:nth-child(8) { animation-delay: 0.16s; }
.chat-item:nth-child(9) { animation-delay: 0.18s; }
.chat-item:nth-child(10) { animation-delay: 0.20s; }

@keyframes chatItemSlide {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

.chat-item:hover {
  background: var(--bg-hover);
}

.chat-item:active {
  transform: scale(0.98);
  background: var(--bg-active);
}

.chat-item.active {
  background: var(--bg-active);
}

.chat-item.active::after {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%) scaleY(0);
  width: 3px;
  height: 24px;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
  animation: activeBarReveal 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes activeBarReveal {
  to { transform: translateY(-50%) scaleY(1); }
}

.chat-item-avatar {
  position: relative;
  flex-shrink: 0;
}

.avatar {
  width: var(--avatar-md);
  height: var(--avatar-md);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.1rem;
  color: #fff;
  text-transform: uppercase;
  flex-shrink: 0;
  user-select: none;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-item:hover .avatar {
  transform: scale(1.05);
}

.avatar-sm { width: var(--avatar-sm); height: var(--avatar-sm); font-size: 0.8rem; }
.avatar-lg { width: var(--avatar-lg); height: var(--avatar-lg); font-size: 2rem; }
.avatar-xl { width: var(--avatar-xl); height: var(--avatar-xl); font-size: 2.5rem; }

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.online-indicator {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 12px; height: 12px;
  background: #2ecc71;
  border-radius: 50%;
  border: 2.5px solid var(--bg-sidebar);
  animation: onlinePulse 2s ease-in-out infinite;
}

@keyframes onlinePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.4); }
  50% { box-shadow: 0 0 0 4px rgba(46, 204, 113, 0); }
}

.chat-item-info { flex: 1; min-width: 0; }

.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.chat-item-name {
  font-weight: 600;
  font-size: 0.93rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.chat-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.chat-item-preview {
  font-size: 0.84rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.chat-item-preview .sender-name {
  color: var(--primary);
  font-weight: 500;
}

.unread-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--primary);
  color: #fff;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  animation: badgePop 0.4s var(--transition-bounce);
}

@keyframes badgePop {
  0% { transform: scale(0); }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* ─── FAB Button ───────────────────────────────────── */
.fab-btn {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px var(--primary-glow);
  z-index: 15;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: fabBounceIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s backwards;
}

@keyframes fabBounceIn {
  from { opacity: 0; transform: scale(0) rotate(-90deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

.fab-btn:hover {
  transform: scale(1.12) rotate(8deg);
  box-shadow: 0 8px 30px var(--primary-glow);
}

.fab-btn:active {
  transform: scale(0.92) rotate(0);
}

.fab-btn svg { width: 24px; height: 24px; }

/* ─── Sidebar Menu (PC) ─── */
.sidebar-menu {
  position: absolute;
  top: 50px;
  left: 10px;
  width: 260px;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  min-width: 240px;
  z-index: var(--z-dropdown);
  animation: sidebarMenuIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: top left;
}

.sidebar-menu.hidden {
  display: none;
}

@keyframes sidebarMenuIn {
  from { opacity: 0; transform: scale(0.92) translateY(-8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.sidebar-menu .menu-item {
  animation: menuItemCascade 0.3s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.sidebar-menu .menu-item:nth-child(1) { animation-delay: 0.02s; }
.sidebar-menu .menu-item:nth-child(2) { animation-delay: 0.04s; }
.sidebar-menu .menu-item:nth-child(3) { animation-delay: 0.06s; }
.sidebar-menu .menu-item:nth-child(4) { animation-delay: 0.08s; }
.sidebar-menu .menu-item:nth-child(5) { animation-delay: 0.10s; }
.sidebar-menu .menu-item:nth-child(6) { animation-delay: 0.12s; }
.sidebar-menu .menu-item:nth-child(7) { animation-delay: 0.14s; }
.sidebar-menu .menu-item:nth-child(8) { animation-delay: 0.16s; }
.sidebar-menu .menu-item:nth-child(9) { animation-delay: 0.18s; }
.sidebar-menu .menu-item:nth-child(10) { animation-delay: 0.20s; }

@keyframes menuItemCascade {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

.profile-trigger-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.profile-trigger-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

.profile-trigger-btn:active {
  transform: scale(0.95);
}

.sidebar-menu-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.2s ease;
  animation: menuItemCascade 0.3s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.sidebar-menu-profile:hover { background: var(--bg-hover); }

.sidebar-profile-info { font-size: 0.9rem; line-height: 1.3; }
.sidebar-profile-info .profile-name { font-weight: 600; color: var(--text-primary); }
.sidebar-profile-info .profile-status { font-size: 0.8rem; color: #2ecc71; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.2s ease;
}

.menu-item:hover {
  background: var(--bg-hover);
  padding-left: 18px;
}

.menu-item:active {
  transform: scale(0.97);
}

.menu-item svg {
  width: 20px; height: 20px;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: color 0.2s ease;
}

.menu-item:hover svg { color: var(--primary); }
.menu-item-danger { color: var(--text-danger); }
.menu-item-danger svg { color: var(--text-danger); }
.menu-item-danger:hover svg { color: var(--text-danger); }

.header-menu-container { position: relative; }

.dropdown-menu {
  position: absolute;
  top: 44px;
  right: 0;
  width: 220px;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  padding: 6px;
  z-index: var(--z-dropdown);
  animation: dropdownIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: top right;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: scale(0.9) translateY(-4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.dropdown-menu.hidden { display: none; }

.dropdown-menu .menu-item {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 8px;
}

/* ═══════════════════════════════════════════════════════
   CHAT AREA
   ═══════════════════════════════════════════════════════ */

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-chat);
  position: relative;
  will-change: transform, opacity;
}

.chat-area::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23000000' fill-opacity='1'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

[data-theme="dark"] .chat-area::before {
  opacity: 0.015;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='1'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
