/* =========================
   Theme Variables
========================= */
:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #0f172a;
  --muted: #64748b;
  --hover: #f1f5f9;
  --accent: #6366f1;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --panel: #0f172a;
  --border: #1e293b;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --hover: #1e293b;
  --accent: #818cf8;
}

/* =========================
   Base
========================= */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* JS 用到：打开侧栏抽屉时禁止页面滚动 */
.no-scroll {
  overflow: hidden;
}

/* =========================
   Topbar
========================= */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

/* Desktop: center the search box */
.topbar-center {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
}

/* Buttons */
.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 10px;
  white-space: nowrap;
}

.icon-btn:hover {
  background: var(--hover);
  opacity: 1;
}

/* Home link + Docs button share same style */
.topbar-home,
.topbar-docs {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  text-decoration: none;
}

/* subtle underline to hint clickable */
.topbar-home .home-text {
  position: relative;
}

.topbar-home .home-text::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: 1px;
  background: currentColor;
  opacity: 0.28;
}

.topbar-home:hover .home-text::after {
  opacity: 0.6;
}

/* Search */
.search-input {
  width: 100%;
  max-width: 520px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.search-input::placeholder {
  color: var(--muted);
}

/* =========================
   Sidebar
========================= */
.sidebar {
  background: var(--panel);
  min-height: calc(100vh - 56px);
  border-right: 1px solid var(--border);
  padding: 12px 10px;
}

.menu-group {
  margin-bottom: 10px;
}

/* Group title (clickable) */
.menu-cat-title {
  position: relative; /* ✅ 伪元素需要 */
  font-size: 14px;
  font-weight: 600;
  padding: 10px 12px 10px 36px;
  margin-top: 6px;
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.menu-cat-title:hover {
  background: var(--hover);
}

.menu-cat-title::before {
  content: '📁';
  position: absolute;
  left: 12px;
  top: 10px;
  font-size: 14px;
}

/* caret */
.menu-cat-title::after {
  content: '▾';
  position: absolute;
  right: 12px;
  top: 11px;
  font-size: 12px;
  opacity: 0.55;
  transition: transform 0.2s ease;
}

.menu-cat-title.open::after {
  transform: rotate(180deg);
}

/* Doc list */
.menu-items {
  list-style: none;
  padding-left: 44px;
  margin: 6px 0 2px;
  display: none;
}

.menu-items.open {
  display: block;
}

.menu-items li {
  margin: 2px 0;
}

.menu-items a {
  display: block;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  position: relative;
}

.menu-items a::before {
  content: '•';
  position: absolute;
  left: -12px;
  color: var(--muted);
}

.menu-items a:hover {
  background: var(--hover);
}

/* Active doc  当前文档高亮（soft active state） */
.menu-items a.active {
  background: rgba(99, 102, 241, 0.12); /* accent 的淡色 */
  color: var(--text);
  font-weight: 500;
  position: relative;
}

/* 左侧细条指示当前位置 */
.menu-items a.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}

/* 深色模式适配 */
[data-theme="dark"] .menu-items a.active {
  background: rgba(129, 140, 248, 0.18);
}
/* =========================
   Content
========================= */
.content {
  background: var(--panel);
  border-radius: 12px;
  padding: 32px;
  margin: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.content h1,
.content h2,
.content h3 {
  font-weight: 600;
}

.content p {
  color: var(--text);
  line-height: 1.7;
}

/* =========================
   Empty state (welcome hint)
========================= */
.empty-state {
  max-width: 560px;
  margin: 40px auto;
  padding: 24px 28px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  text-align: center;
}

.empty-text {
  margin: 0;
  font-size: 15px;
  color: var(--muted);
  line-height: 1.6;
}

/* Desktop / Mobile visibility */
.desktop-only {
  display: block;
}

.mobile-only {
  display: none;
}

@media (max-width: 767.98px) {
  .desktop-only {
    display: none;
  }
  .mobile-only {
    display: block;
  }

  .empty-state {
    margin: 24px 12px;
    padding: 18px 16px;
    font-size: 14px;
  }
}


/* =========================
   Mobile: Sidebar Drawer + Topbar tighter
========================= */
.sidebar-backdrop {
  display: none;
}

@media (max-width: 767.98px) {
  /* Topbar sticky */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 2000;
    padding: 0 12px;
    gap: 8px;
  }

  /* Mobile: hide search */
  .topbar-center {
    display: none;
  }

  /* Mobile: make left buttons compact */
  .topbar-home {
    max-width: 170px;
  }

  .topbar-home .home-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Mobile: Docs button icon only (text hidden) */
  .topbar-docs .docs-text {
    display: none;
  }

  /* Sidebar drawer */
  #sidebar.sidebar {
    position: fixed;
    top: 56px;
    bottom: 0;
    left: 0;

    width: 86%;
    max-width: 340px;

    overflow-y: auto;
    -webkit-overflow-scrolling: touch;  /*✅ iOS：启用弹性滚动 */

    touch-action: pan-y;          /* ✅ Chrome：允许纵向滚动手势 */
    overscroll-behavior: contain; /* ✅ 防止滚动链传到页面 */

    background: var(--panel);
    border-right: 1px solid var(--border);

    transform: translateX(-105%);
    transition: transform 0.2s ease;

    z-index: 1500;
    pointer-events: auto;
  }

  #sidebar.sidebar.is-open {
    transform: translateX(0);
  }

  /* Backdrop */
  #sidebarBackdrop.sidebar-backdrop {
    display: block;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;

    background: rgba(0, 0, 0, 0.35);

    z-index: 1400;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  #sidebarBackdrop.sidebar-backdrop.show {
    opacity: 1;
    pointer-events: auto;
  }

  /* Content spacing */
  .content {
    margin: 12px;
    padding: 18px;
  }
}

  /* Sidebar search hint */
  .sidebar-search-hint {
    padding: 10px 12px;
    margin-bottom: 8px;
    border-radius: 8px;
    font-size: 13px;
    color: var(--muted);
    background: var(--hover);
    display: flex;
    align-items: center;
    gap: 6px;
  }

/* =========================
   Markdown image sizes
========================= */
.content img {
  display: block;
  margin: 16px auto;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

/* Small / Medium / Large (responsive) */
.content img.img-sm {
  max-width: clamp(180px, 60vw, 320px);
}

.content img.img-md {
  max-width: clamp(240px, 85vw, 640px);
}

.content img.img-lg {
  width: 100%;
  max-width: 100%;
}

.content img {
  image-rendering: auto;
}

/* Optional: inline image escape hatch */
.content img.img-inline {
  display: inline;
  margin: 0;
  vertical-align: middle;
  border-radius: 0;
}

/* Search highlight */
.menu-items mark {
  background: rgba(99, 102, 241, 0.25); /* accent 淡色 */
  color: inherit;
  padding: 0 2px;
  border-radius: 4px;
}

[data-theme="dark"] .menu-items mark {
  background: rgba(129, 140, 248, 0.28);
}

/* =========================
   Content background images (light/dark)
========================= */

/* 让 .content 能承载伪元素背景层 */
.content {
  position: relative;
  overflow: hidden;
}

/* 背景图层（默认 light） */
.content::before {
  content: '';
  position: absolute;
  inset: 0;

  background-image: url('/images/BM_Light.jpg');
  background-repeat: no-repeat;
  background-position: right top;   /* 你图 logo 在右上，建议 right top */
  /*background-size: cover;           /* 大图用 cover 更舒服 */
  background-size: 820px auto;
  background-position: right 10px top -40px;
  opacity: 0.18;                    /* ✅ 关键：淡一点，不抢正文 */

  pointer-events: none;             /* ✅ 不挡点击 */
  z-index: 0;
}

/* 让正文始终在背景之上 */
.content > * {
  position: relative;
  z-index: 1;
}

/* Dark 模式换图 + 更低透明度 */
[data-theme="dark"] .content::before {
  background-image: url('/images/BM_Dark.jpg');
  opacity: 0.12;
}

/* 移动端：再淡一些（手机屏更小，背景容易显得压迫） */
@media (max-width: 767.98px) {
  .content::before {
    opacity: 0.12;
    background-position: center top;
  }

  [data-theme="dark"] .content::before {
    opacity: 0.08;
  }
}
