/*
 * TOC drawer (js/modules/toc/).
 *
 * Right-edge slide-in drawer. Closed = a slim vertical 「目录」 tab on the
 * right edge, so the article is never occluded (the old floating panel had
 * to be dragged out of the way). Mobile gets the same drawer over a scrim
 * — it slides in under the sticky top bar.
 */

.toc-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  width: min(320px, 88vw);
  background: var(--surface);
  border-left: 1px solid var(--line-2);
  box-shadow: -14px 0 36px rgb(0 0 0 / 0.1);
  transform: translateX(calc(100% + 40px));
  transition: transform 0.28s cubic-bezier(0.2, 0.7, 0.3, 1);
}

.toc-drawer.is-open {
  transform: translateX(0);
}

.toc-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 12px 18px;
  background: #f8f8f8;
  border-bottom: 1px solid var(--line);
  user-select: none;
}

.toc-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #333;
}

.toc-header__actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 2px;
}

/* 全部折叠 / 全部展开：两个控制始终并列，避免切换后动作入口消失。 */
.toc-fold-control {
  display: grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 26px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #666;
  cursor: pointer;
  transition:
    background-color 0.15s ease,
    color 0.15s ease;
}
.toc-fold-control:hover:not(:disabled) {
  background: #ececec;
  color: #222;
}
.toc-fold-control:disabled {
  color: #aaa;
  cursor: default;
  opacity: 0.5;
}
.toc-fold-control svg {
  width: 18px;
  height: 18px;
}

/* 收起抽屉的 × */
.toc-close-btn {
  position: relative;
  flex: none;
  width: 26px;
  height: 26px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}
.toc-close-btn:hover {
  background: #ececec;
}
.toc-close-btn__x::before,
.toc-close-btn__x::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 1.5px;
  background: #666;
  border-radius: 1px;
}
.toc-close-btn__x::before {
  transform: translate(-50%, -50%) rotate(45deg);
}
.toc-close-btn__x::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}
.toc-close-btn:hover .toc-close-btn__x::before,
.toc-close-btn:hover .toc-close-btn__x::after {
  background: #222;
}

/* ---- 右缘把手（抽屉收起时唯一可见的部分） ---- */

.toc-tab {
  position: fixed;
  top: 50%;
  right: 0;
  z-index: 8900;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  margin: 0;
  padding: 13px 7px 14px;
  border: 1px solid var(--line-2);
  border-right: 0;
  border-radius: 10px 0 0 10px;
  background: var(--frost-bg);
  /* stylelint-disable-next-line property-no-vendor-prefix -- match the frosted top bar */
  -webkit-backdrop-filter: var(--frost-filter);
  backdrop-filter: var(--frost-filter);
  box-shadow: -3px 2px 12px rgb(0 0 0 / 0.08);
  color: #555;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 2px;
  cursor: pointer;
  transform: translateY(-50%);
  transition:
    transform 0.28s cubic-bezier(0.2, 0.7, 0.3, 1),
    opacity 0.2s ease,
    color 0.15s ease;
}

.toc-tab:hover {
  color: #111;
}

.toc-tab.is-hidden {
  transform: translateY(-50%) translateX(110%);
  opacity: 0;
  pointer-events: none;
}

.toc-tab__text {
  writing-mode: vertical-rl;
}

.toc-tab__icon {
  position: relative;
  flex: none;
  width: 14px;
  height: 12px;
}
.toc-tab__icon::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(#666, #666) left top 1px / 14px 2px no-repeat,
    linear-gradient(#666, #666) left top 6px / 10px 2px no-repeat,
    linear-gradient(#666, #666) left top 11px / 12px 2px no-repeat;
}

/* ---- 遮罩：仅移动端；桌面端正文被推开（grid.css），抽屉不压正文 ---- */

.toc-scrim {
  position: fixed;
  inset: 0;
  z-index: 8990;
  background: rgb(30 26 22 / 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

@media (max-width: 1099px) {
  .toc-scrim.is-visible {
    opacity: 1;
    pointer-events: auto;
  }
}

/* ---- 列表 ---- */

.toc-content {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 10px 0 28px;
  overscroll-behavior: contain;
}

.toc-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.toc-item {
  position: relative;
  display: block;
  padding: 5px 14px 5px 16px;
  font-size: 13px;
  line-height: 1.45;
  color: #666;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toc-item:hover {
  color: #349ef3;
  background: #f5f5f5;
}

/* 长标题（尤其每日资讯条目）单行省略，完整文本在 title tooltip 里 */
.toc-item-text {
  display: block;
  margin-left: 8px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.toc-content::-webkit-scrollbar {
  width: 6px;
}
.toc-content::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}
.toc-content::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}
.toc-content::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* 层级缩进 */
.toc-item[data-level='2'] {
  padding-left: 32px;
}
.toc-item[data-level='3'] {
  padding-left: 48px;
}
.toc-item[data-level='4'] {
  padding-left: 64px;
}
.toc-item[data-level='5'] {
  padding-left: 80px;
}
.toc-item[data-level='6'] {
  padding-left: 96px;
}

/* 层级颜色 */
.toc-item[data-level='1'] {
  color: #222;
  font-weight: 600;
}
.toc-item[data-level='2'] {
  color: #444;
  font-weight: 500;
}
.toc-item[data-level='3'] {
  color: #666;
  font-weight: normal;
}
.toc-item[data-level='4'] {
  color: #888;
  font-weight: normal;
}
.toc-item[data-level='5'],
.toc-item[data-level='6'] {
  color: #999;
  font-weight: normal;
}

/* 每日资讯的新闻条目（虚拟条目：callout 标题，非正文标题） */
.toc-item--virtual .toc-item-text {
  font-size: 12.5px;
}

/* 编号 */
.toc-number {
  display: inline-block;
  margin-right: 10px;
  font-weight: inherit;
  color: inherit;
  font-variant-numeric: tabular-nums;
}

/* 折叠按钮（虚拟条目没有——它们是叶子） */
.toc-item .toc-collapse-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.toc-item[data-level='1'] .toc-collapse-btn {
  left: 0;
}
.toc-item[data-level='2'] .toc-collapse-btn {
  left: 16px;
}
.toc-item[data-level='3'] .toc-collapse-btn {
  left: 32px;
}
.toc-item[data-level='4'] .toc-collapse-btn {
  left: 48px;
}
.toc-item[data-level='5'] .toc-collapse-btn {
  left: 64px;
}
.toc-item[data-level='6'] .toc-collapse-btn {
  left: 80px;
}

.toc-collapse-btn::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 6px;
  width: 6px;
  height: 2px;
  background-color: #666;
  transition: transform 0.3s ease;
}

.toc-collapse-btn::after {
  content: '';
  position: absolute;
  left: 6px;
  top: 4px;
  width: 2px;
  height: 6px;
  background-color: #666;
  transition: transform 0.3s ease;
}

/* 折叠状态 */
.toc-item.collapsed .toc-collapse-btn::after {
  transform: scaleY(0);
}

/* 隐藏被折叠的子项 */
.toc-item.toc-hidden {
  display: none !important;
}

/* ---- 移动端：从顶栏下方滑出 ---- */

@media (max-width: 1099px) {
  .toc-drawer {
    top: var(--bar-h, 56px);
    width: min(300px, 84vw);
  }

  .toc-tab {
    padding: 11px 6px 12px;
    font-size: 11px;
  }
}
