/* ============================================
   SIDEBAR - 侧边栏（可折叠）
   ============================================ */

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: width 200ms ease-out;
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

/* Header */
.sidebar-header {
  padding: 16px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  min-width: 0;
}

.sidebar-logo {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  object-fit: contain;
}

.sidebar-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  letter-spacing: -0.01em;
  transition: opacity 150ms ease-out;
}

/* Collapsed header: logo area with expand-on-hover */
.sidebar.collapsed .sidebar-header {
  justify-content: center;
  padding: 16px 0;
  position: relative;
}

.sidebar.collapsed .sidebar-brand {
  position: relative;
  cursor: pointer;
}

.sidebar.collapsed .sidebar-title {
  display: none;
}

/* Toggle button hidden by default in collapsed state */
.sidebar.collapsed .sidebar-toggle {
  position: absolute;
  bottom: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease-out;
  margin-left: 0;
  background: var(--bg-white);
  box-shadow: var(--shadow-sm);
}

.sidebar.collapsed .sidebar-toggle svg {
  width: 12px;
  height: 12px;
}

/* Show toggle on logo hover */
.sidebar.collapsed .sidebar-brand:hover .sidebar-toggle {
  opacity: 1;
  pointer-events: auto;
}

/* Navigation */
.sidebar-nav {
  flex: 1;
  padding: 8px;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 150ms ease-out, color 150ms ease-out;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  position: relative;
}

.nav-item:hover {
  background: var(--gray-100);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-item span:not(.nav-tooltip) {
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 150ms ease-out;
}

/* Collapsed nav items */
.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 10px;
}

.sidebar.collapsed .nav-item span:not(.nav-tooltip) {
  display: none;
}

/* Tooltip (collapsed state only) */
.nav-tooltip {
  display: none;
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--gray-800);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 200;
  box-shadow: var(--shadow-md);
}

.nav-tooltip::before {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-right-color: var(--gray-800);
}

.sidebar.collapsed .nav-item:hover .nav-tooltip {
  display: block;
}

/* 未读数徽章 */
.nav-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  flex-shrink: 0;
}

.nav-badge.hidden {
  display: none;
}

/* 折叠状态下徽章显示在图标右上角 */
.sidebar.collapsed .nav-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  margin-left: 0;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 10px;
  line-height: 16px;
  border: 1.5px solid var(--sidebar-bg);
}

/* Toggle button */
.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: var(--gray-100);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 150ms ease-out, color 150ms ease-out, opacity 150ms ease-out;
  flex-shrink: 0;
  margin-left: auto;
}

.sidebar-toggle:hover {
  background: var(--gray-200);
  color: var(--text);
}

.sidebar-toggle svg {
  width: 16px;
  height: 16px;
  transition: transform 200ms ease-out;
}

.sidebar.collapsed .sidebar-toggle svg {
  transform: rotate(180deg);
}

/* Footer */
.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--sidebar-border);
}

.sidebar-footer .nav-item {
  color: var(--text-tertiary);
}

.sidebar-footer .nav-item:hover {
  color: var(--danger);
  background: var(--danger-light);
}

/* ---------- 移动端抽屉式组件（桌面端隐藏） ---------- */
.mobile-topbar,
.sidebar-overlay {
  display: none;
}

/* ---------- Responsive - 移动端抽屉式 ---------- */
@media (max-width: 768px) {
  /* 抽屉式侧边栏：默认滑出视口左侧 */
  .sidebar {
    width: var(--sidebar-width);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    border-right: 1px solid var(--sidebar-border);
    border-bottom: none;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 200;
    box-shadow: none;
  }

  /* 抽屉打开 */
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }

  /* 移动端忽略 collapsed 状态，抽屉打开时始终完整显示 */
  .sidebar.collapsed {
    width: var(--sidebar-width);
  }

  .sidebar.collapsed .nav-item span:not(.nav-tooltip) {
    display: inline;
  }

  .sidebar.collapsed .sidebar-title {
    display: block;
  }

  .sidebar.collapsed .nav-item {
    justify-content: flex-start;
    padding: 9px 12px;
  }

  .sidebar.collapsed .sidebar-header {
    justify-content: space-between;
    padding: 16px;
  }

  .sidebar.collapsed .sidebar-brand {
    cursor: default;
  }

  /* 折叠按钮在移动端隐藏（用汉堡按钮代替） */
  .sidebar-toggle {
    display: none;
  }

  /* 导航恢复垂直排列 */
  .sidebar-nav {
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 8px;
    gap: 0;
  }

  .nav-item {
    white-space: nowrap;
    margin-bottom: 2px;
    padding: 9px 12px;
  }

  .nav-tooltip {
    display: none !important;
  }

  /* footer 恢复正常分隔 */
  .sidebar-footer {
    border-top: 1px solid var(--sidebar-border);
    padding: 8px;
  }

  /* 顶部标题栏 */
  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    padding: 0 16px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--sidebar-border);
    z-index: 150;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  }

  .mobile-topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
  }

  .mobile-topbar-logo {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    object-fit: contain;
  }

  .mobile-topbar-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    letter-spacing: -0.01em;
  }

  /* 汉堡菜单按钮（标题栏右侧） */
  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    transition: background 150ms ease-out, color 150ms ease-out;
  }

  .mobile-menu-btn:hover {
    background: var(--gray-100);
    color: var(--primary);
  }

  .mobile-menu-btn svg {
    width: 22px;
    height: 22px;
  }

  /* 遮罩层 */
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-out, visibility 0.3s ease-out;
  }

  .sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
  }
}
