.sidebar {
  width: 320px;
  min-width: 320px;
  height: 100%;
  min-height: 0;
  background: white;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

@media (max-width: 767px) {
  .sidebar { width: 100vw; min-width: 0; }
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  flex: 1;
}

.sidebar-logo {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: contain;
  flex-shrink: 0;
}

.offline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e53935;
  flex-shrink: 0;
}

/* New Chat bar (desktop) */
.sidebar-newchat-bar {
  padding: 10px 12px 6px;
  flex-shrink: 0;
}

.newchat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 16px;
  border-radius: 20px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  border: 1.5px solid var(--primary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.newchat-btn:hover { background: var(--primary); color: white; }
.newchat-btn:hover svg { stroke: white; }

/* Mobile FAB */
.newchat-fab {
  position: absolute;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  right: 16px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  z-index: 10;
  cursor: pointer;
  transition: background var(--transition), transform 80ms ease;
  border: none;
  pointer-events: auto;
}
.newchat-fab:hover { transform: scale(1.05); }
.newchat-fab:active { transform: scale(0.97); }

.groups-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.group-section { margin-bottom: 8px; }

.section-label {
  padding: 8px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 0.8px;
}

.group-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background var(--transition);
}
.group-item:hover { background: var(--background); }
.group-item.active { background: var(--primary-light); }
.group-item.active .group-name { color: var(--primary); font-weight: 600; }

.group-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

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

.group-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
}

.group-time {
  font-size: 11px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.group-last-msg {
  font-size: 13px;
  color: var(--text-secondary);
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 12px 8px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  position: relative;
  flex-shrink: 0;
}

.user-footer-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border-radius: var(--radius);
  transition: background var(--transition);
  color: var(--text-primary);
}
.user-footer-btn:hover { background: var(--background); }

.footer-menu {
  position: absolute;
  bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  left: 8px;
  right: 8px;
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  padding: 8px;
  z-index: 100;
  animation: slideUp 150ms ease;
}

.footer-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text-primary);
  transition: background var(--transition);
}
.footer-menu-item:hover { background: var(--background); }
.footer-menu-item.danger { color: var(--error); }
.footer-menu-item.danger:hover { background: #fce8e6; }

.group-item.has-unread { background: var(--surface-variant); }
.unread-name { font-weight: 700; color: var(--text-primary) !important; }
.badge-unread {
  background: #e53935;
  color: white;
  font-size: 11px;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* DM real name in brackets — smaller, muted */
.dm-real-name {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-tertiary);
}

/* Online presence dot on DM avatars */
.group-icon-wrap {
  position: relative;
  flex-shrink: 0;
  display: inline-flex;
}

.online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 11px;
  height: 11px;
  background: #34a853;
  border-radius: 50%;
  border: 2px solid var(--surface);
  pointer-events: none;
}


/* DM right-click context menu */
.dm-context-menu {
  position: fixed;
  z-index: 9999;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 4px 0;
  min-width: 180px;
}

.dm-context-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-primary);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition);
}

.dm-context-menu button:hover {
  background: var(--surface-variant);
}
