/* ========================================
   ??????????(Sidebar.css)
   ??????????????????????   ======================================== */

/* ========================================
   ??????
   ======================================== */

.sidebar {
  position: relative;
  z-index: 110;
  width: var(--sidebar-width);
  height: 100%;
  min-height: 0;
  background: #f6f8fa;
  border-right: 1px solid #d0d7de;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem 1.75rem;
  color: var(--color-text);
  box-shadow: none;
  overflow: hidden;
  font-family: 'LXGWWenKaiMono', ui-monospace, var(--font-family-base);
  /* 只用 GPU 合成层属性，不触发 layout reflow */
}

.sidebar.closed {
  width: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  border-right: none;
  overflow: hidden;
}

/* ========================================
   ????????   ======================================== */

/* ??????? */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;        /* ?????????????? */
  gap: 0.75rem;                          /* ???? */
  margin-bottom: 1rem;
}

/* ????????*/
.sidebar-header h2 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.02em;                /* ???? */
  font-weight: 600;
  color: var(--color-text);
  font-family: 'LXGWWenKaiMono', ui-monospace, var(--font-family-base);
  flex-shrink: 0;                        /* ??????*/
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

/* ?????????? */
.sidebar-title-deco {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  width: 10px;
  flex-shrink: 0;
}

.sidebar-title-deco-block {
  display: block;
  width: 10px;
  height: 3px;
  border-radius: 1px;
  box-shadow: 0 0 0 1px rgba(31, 35, 40, 0.06);
}

.sidebar-title-deco-block--g {
  background: linear-gradient(90deg, #40c057, #51cf66);
}

.sidebar-title-deco-block--r {
  background: linear-gradient(90deg, #fa5252, #ff6b6b);
}

.sidebar-title-deco-block--b {
  background: linear-gradient(90deg, #4c6ef5, #748ffc);
}

/* ========================================
   ??????
   ======================================== */

/* ????????- ????GitHub ?? */
.toggle-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 0.6rem;
  background: rgba(255, 255, 255, 0.7);
  color: var(--color-muted);
  border: 1px solid rgba(208, 215, 222, 0.5);
  border-radius: 6px;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 1px 3px rgba(31, 35, 40, 0.06);
  font-family: 'LXGWWenKaiMono', ui-monospace, var(--font-family-base);
  flex-shrink: 0;
  margin-left: auto;
  opacity: 0.8;
}

/* ?????????- ????GitHub ?? */
.toggle-button:hover {
  background: rgba(255, 255, 255, 1);
  border-color: var(--color-accent);
  color: var(--color-accent);
  opacity: 1;
  transform: translateX(2px);
  box-shadow: 0 2px 6px rgba(9, 105, 218, 0.12);
}

/* ?????????*/
.toggle-button:active {
  transform: translateX(0);
  box-shadow: 0 1px 3px rgba(9, 105, 218, 0.1);
}

/* ========================================
   ????????   ======================================== */

/* ???????? */
.sidebar-content {
  flex: 1;                               /* ?????? */
  overflow-y: auto;                      /* ???? */
  overflow-x: hidden;                    /* ?????? */
  padding-right: 0.5rem;                /* ??????*/
  height: 0;                             /* ?? flex: 1 ????????*/
  min-height: 0;
  /* scroll-behavior: smooth 在移动端影响手势流畅度，去掉 */
  overscroll-behavior: contain;
}

/* ========================================
   ??????   ======================================== */

/* ??????????*/
.sidebar-empty-hint {
  padding: 0.75rem 0.25rem 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--color-muted);
}

.sidebar-empty-hint p {
  margin: 0 0 0.5rem;
}

.sidebar-empty-hint p:first-child {
  font-weight: 600;
  color: var(--color-text);
}

.sidebar-empty-detail {
  font-size: 0.78rem;
  line-height: 1.45;
}

.sidebar-empty-detail code {
  font-size: 0.85em;
  padding: 0.1em 0.35em;
  background: rgba(208, 215, 222, 0.45);
  border-radius: 4px;
}

/* ??????*/
.directory-tree {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}

/* ??????? */
.tree-node {
  user-select: none;                     /* ?????? */
}


/* ?????????? + ????+ ?? */
.folder-shell {
  position: relative;
  border-radius: 8px;
  border: 1px solid var(--folder-border, #d0d7de);
  background: var(--folder-bg, #f6f8fa);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(31, 35, 40, 0.04);
}

.folder-shell::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--folder-bar, #93c5fd);
  border-radius: 8px 0 0 8px;
  pointer-events: none;
}

/* ?????? */
.tree-node-content {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.55rem 0.3rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  /* 消除移动端 300ms 点击延迟 */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  /* 背景色过渡在触控设备上跳过，只在鼠标设备保留 */
  min-width: 0;
}

/* ??????????????????????/?/????????? */
.tree-node-content--folder {
  color: #1b2430;
  background: transparent;
}

.tree-node-content--folder:hover {
  background: var(--folder-wash, #f1f5f9);
}

.tree-node-content--folder .article-count-badge {
  color: var(--folder-muted, #6b7280);
  font-weight: 500;
}

.tree-node-content--folder:hover .article-count-badge {
  color: #5a6678;
}

/* ????????? */
.tree-node-content--file {
  color: #374151;
  background: transparent;
}

.tree-node-content--file:hover {
  background: #eef2f6;
  color: #0969da;
}

.tree-node-content--file:hover .tree-node-icon-wrap--file {
  color: #0969da;
}

/* ???????? .md ??? */
.tree-node-content.selected {
  background: #ddf4ff;
  color: #0969da;
  font-weight: 600;
}

.tree-node-content--folder.selected {
  background: var(--folder-wash-strong, #e8edf3);
  color: #1b2430;
}

.tree-node-content.selected .tree-node-icon-wrap--file {
  color: #0969da;
}

.tree-node-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tree-node-icon-wrap--file {
  color: #64748b;
}

.folder-glyph-svg {
  display: block;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(31, 35, 40, 0.08));
}

.file-glyph-svg {
  display: block;
}

.tree-node-children {
  position: relative;
  margin: 0 0.35rem 0.18rem 0.28rem;
  padding-left: 0.2rem;
}

.tree-node-children > .tree-node + .tree-node {
  margin-top: 0.12rem;
}

/* ????????*/
.tree-node-name {
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-node--file .tree-node-name {
  font-weight: 500;
  font-size: 0.92em;
}

/* ?????? */
.article-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.1rem 0.25rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #6b7280;
  background: transparent;
  border-radius: 4px;
  flex-shrink: 0;
  margin-left: 0.25rem;
  font-variant-numeric: tabular-nums;
}

.tree-node-content.selected .article-count-badge {
  color: #0969da;
}

.tree-node-content--folder.selected .article-count-badge {
  color: var(--folder-muted, #6b7280);
}
/* ?????????????? */
.loading,
.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  padding: 2.5rem 1rem;
  color: var(--color-muted);
  font-size: 0.9rem;
  font-family: 'LXGWWenKaiMono', ui-monospace, var(--font-family-base);
}

/* ???? - ???? - GitHub ?? */
.loading-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #d0d7de;
  border-top-color: #0969da;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ========================================
   ????????   ======================================== */

/* ????????- ???? - GitHub ?? */
.sidebar-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 130;                          /* ?????*/
  width: 40px;
  height: 40px;
  padding: 0;
  background: #ffffff;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(31, 35, 40, 0.12), 0 8px 24px rgba(66, 74, 83, 0.12);
  touch-action: none;                    /* ???????? */
  user-select: none;                     /* ?????? */
  color: #24292f;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* ?????- GitHub ?? */
.sidebar-toggle.dragging {
  box-shadow: 0 3px 12px rgba(31, 35, 40, 0.15), 0 12px 40px rgba(66, 74, 83, 0.15);
  opacity: 0.95;
}

/* ========================================
   ??????- ?????
   ======================================== */

/* 移动端：侧栏为 fixed 抽屉，不占 flex 宽度，正文始终全宽 */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: var(--site-header-height, 48px);
    left: 0;
    bottom: 0;
    width: min(88vw, 300px);
    max-width: min(88vw, 300px);
    height: auto;
    min-height: calc(100dvh - var(--site-header-height, 48px));
    flex: none;
    z-index: 200;
    margin: 0 !important;
    padding: 0.75rem;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #f6f8fa;
    border-right: 1px solid #d0d7de;
    box-shadow: 4px 0 16px rgba(31, 35, 40, 0.12);
    opacity: 1 !important;
    /* 仅 transform，GPU 合成，不触发 reflow */
  }

  .sidebar.open {
    transform: translateX(0);
    pointer-events: auto;
  }

  .sidebar.closed {
    transform: translateX(-100%);
    pointer-events: none;
  }

  /* ????????- GitHub ?? */
  .sidebar-toggle {
    width: 40px;
    height: 40px;
    font-size: 16px;
    background: #ffffff;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(31, 35, 40, 0.12), 0 8px 24px rgba(66, 74, 83, 0.12);
  }
  /* ????????- GitHub ?? */
  .sidebar-toggle.dragging {
    background: #f6f8fa;
    border-color: #0969da;
    box-shadow: 0 3px 12px rgba(31, 35, 40, 0.15), 0 12px 40px rgba(9, 105, 218, 0.15);
  }

  /* ????????*/
  .sidebar-toggle:active {
    transform: scale(0.95);
  }

  /* ??????????*/
  .sidebar-content {
    overflow-x: hidden;
    width: 100%;
  }

  /* ???????? */
  .directory-tree {
    overflow-x: hidden;
    width: 100%;
  }

  /* ????????*/
  .sidebar-header h2 {
    font-size: 1.1rem;
    margin: 0.5rem 0;
  }

  /* ????????????*/
  .article-count-badge {
    min-width: 1.1rem;
    height: 1.1rem;
    padding: 0.05rem 0.25rem;
    font-size: 0.65rem;
    margin-left: 0.3rem;
  }
}

/* ????? (769px ??) */
@media (min-width: 769px) {
  .sidebar {
    position: static;
    top: auto;
    left: auto;
    bottom: auto;
    z-index: 110;
    height: 100%;
    min-height: 0;
    box-shadow: none;
    margin-left: 0;
  }

  /* 桌面 open：恢复到原始位置和占位 */
  .sidebar.open {
    transform: translateX(0);
    margin-left: 0;
    opacity: 1;
    pointer-events: auto;
  }

  /* ??????????*/
  .sidebar-toggle {
    display: none !important;            /* ???????? */
  }
}
