/* 侧边栏基础样式 */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  box-shadow: 2px 0 8px var(--sidebar-shadow);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: transform 0.3s ease;
}

.sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sidebar-width)));
}

/* 侧边栏头部 */
.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-header img {
  width: 32px;
  height: 32px;
}

.sidebar-header a {
  color: var(--sidebar-text);
  text-decoration: none;
  font-weight: 600;
  font-size: 1.1rem;
}

.sidebar-header a:hover {
  color: var(--sidebar-primary);
}

/* 侧边栏内容 */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

/* 分类标题 */
.sidebar-category {
  padding: 8px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--sidebar-text);
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 8px;
}

.sidebar-category:first-child {
  margin-top: 0;
}

/* 工具链接 */
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
}

.sidebar-item:hover {
  background: var(--sidebar-hover);
  border-left-color: var(--sidebar-primary);
}

.sidebar-item.active {
  background: var(--sidebar-active);
  border-left-color: var(--sidebar-primary);
  font-weight: 500;
}

.sidebar-item i {
  width: 20px;
  text-align: center;
  opacity: 0.8;
}

/* 侧边栏底部 */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  background: var(--sidebar-hover);
  border: none;
  border-radius: 6px;
  color: var(--sidebar-text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sidebar-toggle-btn:hover {
  background: var(--sidebar-active);
}

/* 展开按钮（收起状态时显示） */
.sidebar-expand-btn {
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: var(--sidebar-toggle-size);
  height: 80px;
  background: var(--sidebar-bg);
  border: 1px solid var(--sidebar-border);
  border-left: none;
  border-radius: 0 8px 8px 0;
  box-shadow: 2px 0 8px var(--sidebar-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
}

.sidebar-expand-btn i {
  color: var(--sidebar-text);
  font-size: 1rem;
}

.sidebar-expand-btn:hover {
  width: 48px;
  background: var(--sidebar-hover);
}

.sidebar.collapsed ~ .sidebar-expand-btn {
  opacity: 1;
  pointer-events: auto;
}

/* 主内容区域偏移 */
body.sidebar-open {
  margin-left: var(--sidebar-width);
}

body.sidebar-collapsed {
  margin-left: 0;
}

/* 主题切换 */
.sidebar-theme-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  margin-top: 8px;
}

.sidebar-theme-toggle span {
  font-size: 0.85rem;
  color: var(--sidebar-text);
}

.theme-switch-small {
  position: relative;
  width: 44px;
  height: 22px;
}

.theme-switch-small input {
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-switch-small label {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--sidebar-border);
  border-radius: 22px;
  transition: 0.3s;
}

.theme-switch-small label::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: 0.3s;
}

.theme-switch-small input:checked + label {
  background-color: var(--sidebar-primary);
}

.theme-switch-small input:checked + label::before {
  transform: translateX(22px);
}

/* 滚动条样式 */
.sidebar-content::-webkit-scrollbar {
  width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: var(--sidebar-border);
  border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
  background: var(--sidebar-primary);
}

/* 遮罩层 */
.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* 移动端汉堡菜单按钮 */
.sidebar-mobile-toggle {
  display: none;
}

/* 移动端适配 */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    max-width: 300px;
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
  }

  /* 移动端不推移页面内容 */
  body.sidebar-open {
    margin-left: 0;
  }

  body.sidebar-open main {
    margin-left: 0 !important;
  }

  /* 移动端侧边栏打开时禁止 body 滚动 */
  body.sidebar-mobile-open {
    overflow: hidden;
  }

  /* 移动端显示遮罩层 */
  .sidebar:not(.collapsed) ~ .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  /* 工具链接触摸目标优化 */
  .sidebar-item {
    min-height: 44px;
    padding: 12px 16px;
  }

  /* 移动端隐藏桌面端展开按钮 */
  .sidebar-expand-btn {
    display: none !important;
  }

  /* 移动端汉堡菜单按钮 */
  .sidebar-mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 12px;
    left: 12px;
    width: 44px;
    height: 44px;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: 10px;
    box-shadow: 0 2px 8px var(--sidebar-shadow);
    cursor: pointer;
    z-index: 998;
    transition: background 0.2s ease, box-shadow 0.2s ease;
  }

  .sidebar-mobile-toggle i {
    color: var(--sidebar-primary);
    font-size: 1.1rem;
  }

  .sidebar-mobile-toggle:hover {
    background: var(--sidebar-hover);
    box-shadow: 0 4px 12px var(--sidebar-shadow);
  }

  /* 移动端侧边栏打开时隐藏汉堡按钮 */
  body.sidebar-mobile-open .sidebar-mobile-toggle {
    display: none;
  }
}
