:root { --header-h: 60px; }

/* ===== Scoped Sidebar（避免被全局样式影响） ===== */
.page-with-sidebar .sidebar {
  position: sticky;            /* 桌面吸顶 */
  top: var(--header-h, 60px);  /* 与 header 高度一致 */
  align-self: flex-start;
  flex: 0 0 220px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 16px;
  box-sizing: border-box;
  z-index: 2;                  /* 高于内容，但低于 header(1000) 就行 */
  isolation: isolate;          /* 隔离内部层叠上下文，减少外部影响 */
}

/* 列表与内边距重置 */
.page-with-sidebar .sidebar ul {
  margin: 0;
  padding: 0;
  list-style: none;
}
.page-with-sidebar .sidebar li {
  margin: 6px 0;
  padding: 0;
}

/* 链接的重置与样式 */
.page-with-sidebar .sidebar a {
  display: inline-block;
  text-decoration: none;
  padding: 6px 8px;
  border-radius: 6px;
  line-height: 1.2;
}
.page-with-sidebar .sidebar a:hover {
  background: #f5f5f5;
}

/* 按钮在侧栏内的重置（防止被全局按钮样式影响） */
.page-with-sidebar .sidebar button {
  appearance: none;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #0f766e;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.page-with-sidebar .sidebar button:hover {
  background: #f0fdfa;
  border-color: #99f6e4;
}

/* 小标题 */
.page-with-sidebar .sidebar h3 {
  margin: 0 0 8px 0;
  font-size: 1rem;
  color: #374151;
}

/* 整体布局容器（保持你原来的结构，但加强约束） */
.page-with-sidebar {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1rem;
  display: flex;
  align-items: flex-start;
  gap: 24px;
  box-sizing: border-box;
}

/* 右侧内容区避免溢出 */
.page-with-sidebar .content {
  flex: 1 1 auto;
  min-width: 0;
}

/* ===== 移动端：抽屉式侧栏 ===== */
@media (max-width: 768px) {
  .page-with-sidebar {
    display: block;
    margin: 1rem auto;
  }
  .page-with-sidebar .sidebar {
    position: fixed;
    top: var(--header-h, 60px);
    left: 0;
    height: calc(100vh - var(--header-h, 60px));
    width: 260px;               /* 移动端稍宽一点更好点按 */
    overflow: auto;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 0 8px 24px rgba(0,0,0,.15);
    display: block;             /* 默认存在，只是移出视口 */
    z-index: 999;               /* 高于内容 */
  }
  .page-with-sidebar .sidebar.active {
    transform: translateX(0);
  }
}

/* 防止全局 img / table 等撑破布局（再次兜底） */
.page-with-sidebar img, 
.page-with-sidebar canvas, 
.page-with-sidebar video, 
.page-with-sidebar svg {
  max-width: 100%;
  height: auto;
}
@media (max-width: 768px) {
  .page-with-sidebar table { max-width: 100%; table-layout: fixed; }
  .page-with-sidebar th, 
  .page-with-sidebar td { word-break: break-word; overflow-wrap: anywhere; }
}