/* sidebar.css - 修复嵌套折叠、增加 Tooltip 和完美居中 */
* {
  box-sizing: border-box;
}

/* ============ 侧边栏主容器 ============ */
.sidebar {
  width: 280px;
  height: 100vh;
  background-color: #fafafa;
  border-right: 1px solid #e8e8e8;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  flex-shrink: 0;
  z-index: 100; /* 确保层级 */
}

/* 折叠状态 */
.sidebar.collapsed {
  width: 72px;
}

/* ============ 居中和隐藏逻辑优化 ============ */

/* 1. 隐藏文字和标题 */
.sidebar.collapsed .menu-text,
.sidebar.collapsed .group-text,
.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .group-arrow {
  display: none; /* 彻底隐藏，避免影响 Flex 布局 */
}

.sidebar.collapsed .sidebar-collapse-btn {
  transform: rotate(180deg);
}

/* 2. 分组逻辑 */
/* 折叠状态下，隐藏一级分组的标题 */
.sidebar.collapsed .menu-group > .group-title {
  display: none;
}

/* 折叠状态下，强制显示所有子项容器 */
.sidebar.collapsed .menu-group > .group-items {
  display: block !important;
  max-height: none !important;
  padding-left: 0 !important;
}

/* 隐藏嵌套分组的标题 */
.sidebar.collapsed .group-items .menu-group > .group-title {
  display: none;
}

/* 显示嵌套分组的子项 */
.sidebar.collapsed .group-items .menu-group > .group-items {
  display: block !important;
  max-height: none !important;
  padding-left: 0 !important;
}

/* 3. 图标居中核心样式 */
.sidebar.collapsed .menu-item,
.sidebar.collapsed .sidebar-footer-item {
  justify-content: center;
  padding: 0; /* 清除内边距，完全靠 Flex 居中 */
  width: 44px; /* 固定宽度 */
  height: 44px; /* 固定高度 */
  margin: 8px auto; /* 水平居中 */
  border-radius: 10px; /* 稍微圆润一点 */
  gap: 0; /* 移除图标和文字间的间距 */
}

/* 头部调整 */
.sidebar.collapsed .sidebar-header {
  justify-content: center;
  padding: 16px 0;
}

.sidebar.collapsed .sidebar-collapse-btn {
  margin: 0;
}

/* ============ 侧边栏头部 ============ */
.sidebar-header {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e8e8e8;
  min-height: 64px;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 20px;
  font-weight: 600;
  color: #1a1a1a;
  white-space: nowrap;
  transition: opacity 0.2s;
}

.sidebar-collapse-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.3s;
  flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
  background-color: #f0f0f0;
}

/* ============ 汉堡菜单按钮 ============ */
.sidebar-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  margin: 12px auto;
  flex-shrink: 0;
}

.sidebar.collapsed .sidebar-toggle {
  display: flex;
}

.sidebar.collapsed .sidebar-header {
  display: none;
}

.sidebar-toggle:hover {
  background-color: #f0f0f0;
}

/* ============ 侧边栏内容区 ============ */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
  scrollbar-width: thin;
  scrollbar-color: #d0d0d0 transparent;
  min-height: 0;
}

.sidebar-content::-webkit-scrollbar {
  width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background-color: #d0d0d0;
  border-radius: 3px;
}

.sidebar.collapsed .sidebar-content {
  padding: 4px 0; /* 减少 Padding，靠 margin auto 居中 */
}

.sidebar.collapsed .sidebar-content::-webkit-scrollbar {
  width: 0px; /* 折叠时隐藏滚动条更美观，或者设极细 */
}

/* ============ 底部固定区域 ============ */
.sidebar-footer {
  flex-shrink: 0;
  padding: 8px;
  border-top: 1px solid #e8e8e8;
  background-color: #fafafa;
}

.sidebar.collapsed .sidebar-footer {
  padding: 8px 0;
}

/* ============ 菜单项 ============ */
.menu-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  margin: 2px 0;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  color: #1a1a1a;
  transition: all 0.2s;
  position: relative;
  gap: 12px; /* 图标和文字的间距 */
  min-height: 44px;
}

.menu-item:hover {
  background-color: #f0f0f0;
}

.menu-item.active {
  background-color: #4c6ef5 !important;
  color: #ffffff;
}

.menu-item.active .menu-icon svg {
  stroke: #ffffff;
}

.menu-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-icon svg {
  width: 22px;
  height: 22px;
  stroke: #5c5c5c;
  transition: stroke 0.2s;
}

.menu-item:hover .menu-icon svg {
  stroke: #1a1a1a;
}

.menu-text {
  font-size: 15px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* ============ 折叠组 ============ */
.menu-group {
  margin: 4px 0;
}

.group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  cursor: pointer;
  border-radius: 8px;
  transition: background-color 0.2s;
  min-height: 40px;
  gap: 8px;
}

.group-title:hover {
  background-color: #f0f0f0;
}

.group-text {
  font-size: 14px;
  font-weight: 500;
  color: #8c8c8c;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.group-arrow {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  stroke: #8c8c8c;
  transition: transform 0.3s;
  transform: rotate(-90deg);
}

.menu-group.expanded .group-arrow {
  transform: rotate(0deg);
}

.group-items {
  max-height: 0;
  overflow: hidden;
  padding-left: 16px;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.menu-group.expanded > .group-items {
  max-height: 2000px;
}

/* 嵌套组样式 */
.group-items .menu-group {
  margin-left: 0;
}

.group-items .group-title {
  padding-left: 8px;
  font-size: 13px;
}

/* ============ 底部项 ============ */
.sidebar-footer-item {
  display: flex;
  align-items: center;
  padding: 12px 12px;
  margin: 4px 0;
  cursor: pointer;
  border-radius: 8px;
  transition: background-color 0.2s;
  gap: 12px;
  min-height: 44px;
  position: relative;
}

.sidebar-footer-item:hover {
  background-color: #f0f0f0;
}

.sidebar-footer-item .menu-icon {
  width: 24px;
  height: 24px;
}

.sidebar-footer-item .menu-icon svg {
  width: 22px;
  height: 22px;
  stroke: #5c5c5c;
}

/* ============ Tooltip 样式 (新增) ============ */
.sidebar-tooltip {
  position: fixed;
  z-index: 9999;
  padding: 6px 12px;
  background-color: #000000;
  color: #ffffff;
  font-size: 13px;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-10px);
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  font-weight: 500;
}

.sidebar-tooltip.visible {
  opacity: 1;
  transform: translateX(0);
}

/* Tooltip 左侧小箭头 */
.sidebar-tooltip::before {
  content: '';
  position: absolute;
  top: 50%;
  left: -4px;
  transform: translateY(-50%);
  border-width: 4px 4px 4px 0;
  border-style: solid;
  border-color: transparent #000000 transparent transparent;
}

/* 深色模式下 Tooltip 调整为白色背景 */
body.dark-theme .sidebar-tooltip {
  background-color: #ffffff;
  color: #000000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

body.dark-theme .sidebar-tooltip::before {
  border-color: transparent #ffffff transparent transparent;
}

/* ============ 弹出菜单 ============ */
.popup-menu {
  position: fixed;
  background: #ffffff;
  border: 1px solid #e8e8e8;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: all 0.2s;
  z-index: 9999;
  min-width: 200px;
  max-height: 400px;
  overflow-y: auto;
}

.popup-menu.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.popup-menu-content {
  padding: 8px;
}

.popup-menu-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  cursor: pointer;
  border-radius: 8px;
  transition: background-color 0.2s;
  gap: 12px;
  font-size: 15px;
  color: #1a1a1a;
}

.popup-menu-item:hover {
  background-color: #f5f5f5;
}

/* 语言和主题选项通用 */
.language-prefix {
  font-size: 13px;
  font-weight: 600;
  color: #8c8c8c;
  min-width: 28px;
}

.language-label, .theme-label {
  flex: 1;
}

.theme-option {
  position: relative;
}

.theme-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}

.theme-check {
  opacity: 0;
}

.theme-option.active .theme-check {
  opacity: 1;
}

/* ============ 响应式设计 ============ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-280px);
  }
  
  .sidebar.collapsed {
    transform: translateX(-72px);
  }
  
  .sidebar.mobile-open {
    transform: translateX(0);
  }
}

/* ============ 用户栏样式 ============ */

/* 用户头像（小） */
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-initial {
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
}

.user-name {
  font-size: 14px;
  font-weight: 500;
  color: #1a1a1a;
}

/* 用户栏底部项 */
.user-footer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px !important;
  border-top: 1px solid #e8e8e8;
  margin-top: 4px;
}

/* 折叠状态下只显示头像 */
.sidebar.collapsed .user-footer-item {
  justify-content: center;
  padding: 0 !important;
  width: 44px;
  height: 44px;
  margin: 8px auto;
  border-top: none;
}

.sidebar.collapsed .user-avatar {
  width: 32px;
  height: 32px;
}

.sidebar.collapsed .user-initial {
  font-size: 16px;
}

/* 用户菜单弹窗样式 */
.user-popup-menu {
  min-width: 240px;
}

.user-menu-header {
  display: flex;
  align-items: center;
  padding: 16px 12px;
  gap: 12px;
}

.user-avatar-large {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-avatar-large .user-initial {
  font-size: 20px;
  font-weight: 700;
}

.user-info {
  flex: 1;
}

.user-name-large {
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
}

.user-menu-divider {
  height: 1px;
  background-color: #e8e8e8;
  margin: 4px 8px;
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}

.user-menu-item svg {
  flex-shrink: 0;
  stroke: #5c5c5c;
}

.user-menu-item:hover svg {
  stroke: #1a1a1a;
}

/* ============ 深色主题适配 ============ */
body.dark-theme .user-name,
body.dark-theme .user-name-large {
  color: #e0e0e0;
}

body.dark-theme .user-footer-item {
  border-top-color: #2d2d2d;
}

body.dark-theme .user-menu-divider {
  background-color: #2d2d2d;
}

body.dark-theme .user-menu-item svg {
  stroke: #a0a0a0;
}

body.dark-theme .user-menu-item:hover svg {
  stroke: #e0e0e0;
}

/* ============ 深色主题 ============ */
body.dark-theme .sidebar,
body.dark-theme .sidebar-footer {
  background-color: #111827;
  border-right-color: #2d2d2d;
}

body.dark-theme .sidebar-title,
body.dark-theme .menu-item,
body.dark-theme .sidebar-footer-item {
  color: #e0e0e0;
}

body.dark-theme .sidebar-header,
body.dark-theme .sidebar-footer {
  border-color: #2d2d2d;
}

body.dark-theme .menu-item:hover,
body.dark-theme .group-title:hover,
body.dark-theme .sidebar-footer-item:hover {
  background-color: #2d2d2d;
}

body.dark-theme .menu-item.active {
  background-color: #4c6ef5;
  color: #ffffff;
}

body.dark-theme .menu-icon svg,
body.dark-theme .group-arrow {
  stroke: #a0a0a0;
}

body.dark-theme .menu-item:hover .menu-icon svg,
body.dark-theme .sidebar-footer-item:hover .menu-icon svg {
  stroke: #e0e0e0;
}

body.dark-theme .sidebar-collapse-btn:hover,
body.dark-theme .sidebar-toggle:hover {
  background-color: #2d2d2d;
}

body.dark-theme .popup-menu {
  background-color: #1e1e1e;
  border-color: #2d2d2d;
}

body.dark-theme .popup-menu-item {
  color: #e0e0e0;
}

body.dark-theme .popup-menu-item:hover {
  background-color: #2d2d2d;
}