/* 侧边栏样式 */
:root {
  --sidebar-width: 200px;
  --sidebar-collapsed-width: 0px;
  --sidebar-toggle-size: 40px;
  --sidebar-bg: #ffffff;
  --sidebar-border: #e5e5ea;
  --sidebar-text: #2c3e50;
  --sidebar-hover: #f5f5f5;
  --sidebar-active: rgba(74, 144, 226, 0.15);
  --sidebar-primary: #4a90e2;
  --sidebar-shadow: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
  --sidebar-bg: #1c1c1e;
  --sidebar-border: #38383a;
  --sidebar-text: #ffffff;
  --sidebar-hover: #2c2c2e;
  --sidebar-active: rgba(74, 144, 226, 0.25);
  --sidebar-shadow: rgba(0, 0, 0, 0.3);
}

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

.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);
}

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

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

  /* 遮罩层 */
  .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:not(.collapsed)~.sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }
}


/* 页面主内容适配 */
body.sidebar-open main {
  padding-top: 20px;
  margin-left: 0;
  /* main 已经在 body 内，不需要额外 margin */
}

body.sidebar-collapsed main {
  padding-top: 20px;
}

/* 覆盖 common.css 中的 main padding */
body.sidebar-open main,
body.sidebar-collapsed main {
  /* padding-top: 20px !important; */
}

/* 移除原有 navbar 占位 */
body.sidebar-open .navbar,
body.sidebar-collapsed .navbar {
  display: none;
}

/* 移除原有 footer */
body.sidebar-open footer,
body.sidebar-collapsed footer {
  display: none;
}