/* 左侧边栏（YouTube 式导航架）+ 文件夹选择器 + 轻提示 toast —— 2026-08-24 重构
   设计语言与全站一致：宣纸底 / 发丝线框 / 墨色为骨、朱砂只在事件。
   与 YouTube 对齐的结构（2026-08-24）：
   - 品牌与 ☰ 归 masthead（shelf.css），侧栏从 masthead 下缘开始、只放导航
   - 全宽 224px ↔ rail 72px；rail 里图标在上、小字标签在下（YouTube 口径，不是纯图标）
   - 宽屏（≥901px）常驻，窄屏（≤900px）抽屉（☰ + 遮罩） */
:root {
  --sidebar-w: 224px;
  --sidebar-rail-w: 72px;
}

/* ---------- 边栏本体 ---------- */
#sidebar {
  position: fixed;
  top: calc(var(--mast-h) + env(safe-area-inset-top));
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg);
  z-index: 45; /* masthead 46 之下；阅读页小窗 34 / 词气泡 35 之上，无侧栏视图整体隐藏 */
  display: none; /* 默认不出现：只有书架/生词本视图（body.with-sidebar）才在 */
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 12px 0 20px;
}
body.with-sidebar #sidebar { display: flex; }

#sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 22, 14, 0.35);
  z-index: 44;
  display: none;
}
#sidebar-backdrop:not([hidden]) { display: block; }

/* ---------- 导航项（图标 + 文字）---------- */
.sidebar-nav { padding: 0 12px; flex: none; }
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  background: none;
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-item:hover { background: var(--hover); }
.sidebar-item:active { background: var(--active-surface); }
/* 选中态（YouTube：填充面 + 加重字，不换字色） */
.sidebar-item.is-active {
  background: var(--active-surface);
  font-weight: 600;
}
.sii {
  flex: none;
  width: 22px;
  text-align: center;
  font-size: 15px;
  line-height: 1;
}
.sit { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- 文件夹区 ---------- */
.sidebar-section {
  margin-top: 12px;
  padding: 8px 12px 24px;
  border-top: 1px solid var(--line);
  flex: 1;
}
.sidebar-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 6px 6px;
}
.sidebar-section-title {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
}
#sidebar-add, #sidebar-edit {
  font-family: var(--sans);
  font-size: 11.5px;
  color: var(--ink-soft);
  background: none;
  border: none;
  padding: 4px 7px;
  border-radius: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#sidebar-add:hover, #sidebar-edit:hover { color: var(--accent); background: var(--hover); }

.sidebar-folders-empty {
  font-family: var(--sans);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--ink-stone);
  padding: 6px 8px 2px;
}

/* 文件夹行 */
.sidebar-folder {
  display: flex;
  align-items: center;
  border-radius: 10px;
  min-height: 40px;
  padding: 0 4px 0 2px;
}
.sidebar-folder:hover { background: var(--hover); }
.sidebar-folder.is-active { background: var(--active-surface); }
.sidebar-folder-name {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  background: none;
  border: none;
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-folder-name::before {
  content: '📁';
  font-size: 14px;
  width: 22px;
  text-align: center;
  flex: none;
}
.sidebar-folder.is-active .sidebar-folder-name { font-weight: 600; }
.sidebar-folder-count {
  font-family: var(--sans);
  font-size: 11px;
  color: var(--ink-stone);
  background: var(--tag-bg);
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: auto; /* 挤到最右，动作按钮之前 */
  flex: none;
}

/* 行内动作（✎ ✕）：桌面 hover 浮现；编辑态（触屏）常驻 */
.sidebar-folder-actions { display: none; gap: 2px; align-items: center; flex: none; }
.sidebar-folder:hover .sidebar-folder-actions,
.sidebar-folder.force-actions .sidebar-folder-actions,
.sidebar-folder.confirming .sidebar-folder-actions { display: flex; }
.sidebar-folder-act {
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1;
  color: var(--ink-stone);
  background: none;
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-folder-act:hover { color: var(--accent); background: var(--hover); }
.sidebar-folder-act.is-danger { color: var(--accent); }
.sidebar-confirm-hint {
  font-family: var(--sans);
  font-size: 10.5px;
  color: var(--ink-stone);
  padding: 0 4px;
}

/* 行内输入（新建 / 重命名） */
.sidebar-folder--new, .sidebar-folder.is-editing {
  padding: 4px 4px 4px 6px;
  min-height: 0;
}
.sidebar-folder--new .sidebar-folder-name::before { display: none; }
.sidebar-input {
  flex: 1;
  min-width: 0;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink);
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  outline: none;
}
.sidebar-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.sidebar-act {
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--ink-stone);
  cursor: pointer;
  flex: none;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-act:hover { color: var(--accent); background: var(--hover); }

/* ---------- 书架布局：宽屏让出版心 ---------- */
/* ≥901px 静态常驻（iPad 横屏 1024 / 桌面）；≤900px 抽屉（iPad 竖屏 768 也走抽屉，224px 常驻太挤）
   YouTube 式：内容区不收版心，铺满侧栏右侧全部空间（书架海报墙靠列数自适应） */
@media (min-width: 901px) {
  body.with-sidebar #app {
    margin-left: var(--sidebar-w);
    max-width: none;
    transition: margin-left 0.2s ease;
  }
  html.sidebar-rail body.with-sidebar #app { margin-left: var(--sidebar-rail-w); }
  #sidebar { transition: width 0.2s ease; }
}

/* 窄屏：抽屉滑入 */
@media (max-width: 900px) {
  #sidebar {
    width: min(280px, 84vw);
    transform: translateX(-100%);
    transition: transform 0.26s cubic-bezier(0.22, 0.9, 0.3, 1);
  }
  #sidebar.open {
    transform: none;
    box-shadow: 12px 0 32px -18px rgba(0, 0, 0, 0.5);
  }
}
@media (prefers-reduced-motion: reduce) {
  #sidebar, body.with-sidebar #app { transition: none; }
}

/* 文件夹视图展签行的「‹ 全部文章」退出钮 */
.list-info-back {
  font-family: var(--sans);
  font-size: 11px;
  color: var(--accent);
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  margin-right: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.list-info-back:active { background: var(--accent-wash); }

/* ---------- 文件夹选择器面板 ---------- */
.folder-picker {
  position: fixed;
  z-index: 60;
  width: 248px;
  max-height: min(62vh, 420px);
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 44px -18px rgba(42, 38, 30, 0.5);
  overflow: hidden;
}
.fp-head {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--ink-stone);
  padding: 11px 14px 6px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fp-list { overflow-y: auto; padding: 6px; }
.fp-rows { display: flex; flex-direction: column; gap: 1px; }
.fp-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: 7px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.fp-row:hover { background: var(--hover); }
.fp-row input {
  width: 16px;
  height: 16px;
  flex: none;
  accent-color: var(--accent);
}
.fp-name {
  flex: 1;
  min-width: 0;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fp-count {
  font-family: var(--sans);
  font-size: 11px;
  color: var(--ink-stone);
  flex: none;
}
.fp-empty {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-stone);
  padding: 10px 8px;
  margin: 0;
}
.fp-new {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--line);
}
.fp-new-input {
  flex: 1;
  min-width: 0;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
  outline: none;
}
.fp-new-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.fp-new-add {
  flex: none;
  width: 30px;
  height: 30px;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1;
  color: var(--ink-soft);
  background: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.fp-new-add:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- toast 轻提示 ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(64px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  max-width: min(82vw, 420px);
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink);
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 18px;
  box-shadow: 0 12px 28px -14px rgba(42, 38, 30, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 80;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.is-error { border-color: var(--accent); color: var(--accent); }

/* ---------- YouTube 式 rail（收起态，≥901px）：72px 窄轨，图标在上、小字标签在下 ---------- */
@media (min-width: 901px) {
  html.sidebar-rail #sidebar {
    width: var(--sidebar-rail-w);
    padding-top: 8px;
  }
  html.sidebar-rail #sidebar .sidebar-nav { padding: 0 2px; }
  /* 导航项：竖排（图标 + 10px 标签），YouTube rail 保留文字 */
  html.sidebar-rail #sidebar .sidebar-item {
    flex-direction: column;
    gap: 5px;
    padding: 14px 0 12px;
    border-radius: 10px;
  }
  html.sidebar-rail #sidebar .sii { width: auto; font-size: 18px; }
  html.sidebar-rail #sidebar .sit {
    max-width: 100%;
    font-size: 10px;
    letter-spacing: 0.01em;
    text-align: center;
  }
  /* 文件夹区：区标题隐藏（rail 里没有横向空间），＋新建变纯图标 */
  html.sidebar-rail #sidebar .sidebar-section { padding: 8px 2px 20px; }
  html.sidebar-rail #sidebar .sidebar-section-head { justify-content: center; padding: 4px 0 6px; }
  html.sidebar-rail #sidebar .sidebar-section-title,
  html.sidebar-rail #sidebar #sidebar-edit { display: none; }
  html.sidebar-rail #sidebar #sidebar-add {
    font-size: 0;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
  }
  html.sidebar-rail #sidebar #sidebar-add::before { content: '＋'; font-size: 16px; line-height: 1; }
  html.sidebar-rail #sidebar .sidebar-folders-empty { display: none; }
  /* 文件夹行：📁 在上、名字截断成小字在下（与导航项同构） */
  html.sidebar-rail #sidebar .sidebar-folder { padding: 0; min-height: 0; }
  html.sidebar-rail #sidebar .sidebar-folder-name {
    flex-direction: column;
    gap: 4px;
    padding: 12px 2px 10px;
    font-size: 10px;
    text-align: center;
    white-space: normal;
  }
  html.sidebar-rail #sidebar .sidebar-folder-name::before { font-size: 17px; width: auto; }
  /* 文件夹名在 rail 里只留一行（超出截断），计数与动作按钮隐藏 */
  html.sidebar-rail #sidebar .sidebar-folder-name > span:not(.sidebar-folder-count) { display: none; }
  html.sidebar-rail #sidebar .sidebar-folder-count { display: none; }
  html.sidebar-rail #sidebar .sidebar-folder-actions { display: none !important; }
}

/* ---------- 细节打磨：主题化细滚动条 + 聚焦轮廓 ---------- */
#sidebar::-webkit-scrollbar,
.folder-picker .fp-list::-webkit-scrollbar { width: 5px; }
#sidebar::-webkit-scrollbar-thumb,
.folder-picker .fp-list::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 3px;
}
#sidebar::-webkit-scrollbar-thumb:hover,
.folder-picker .fp-list::-webkit-scrollbar-thumb:hover { background: var(--ink-stone); }
#sidebar::-webkit-scrollbar-track,
.folder-picker .fp-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-folder-name:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
