/* ============================================================
   Tri-Sites Sidebar — 左侧固定侧栏 + 品牌矩阵切换器
   v2.1 — 移动端抽屉优化（宽度/手势/安全区/hamburger动画）
   ============================================================ */

/* ---------- 侧栏容器 ---------- */
.sb {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w, 220px);
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  /* iOS 安全区 */
  padding-top: 0;
}

/* ---------- 旧导航元素隐藏（全站通用） ---------- */
/* 当共享 sidebar 加载后，自动隐藏各站点遗留的旧导航组件 */
#lang-switcher,
.mobile-topbar,
#hamburger,
.drawer-backdrop,
.nav-wrap,
.g-nav,
.bottom-nav,
.drawer-nav,
.sidebar:not(#triSidebar) {
  display: none !important;
}

/* ---------- 主内容区 ---------- */
.sb-main {
  margin-left: var(--sidebar-w, 220px);
  min-height: 100vh;
  transition: margin-left 0.25s;
}

/* ---------- 品牌区域 ---------- */
.sb-brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--line);
  position: relative;
}
.sb-brand-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: none;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  transition: all 0.15s;
  cursor: pointer;
  text-align: left;
}
.sb-brand-btn:hover {
  background: var(--brand-l);
  border-color: var(--line-h);
}
.sb-brand-btn .sb-logo { font-size: 24px; line-height: 1; }
.sb-brand-btn .sb-name {
  font-weight: 800; font-size: 16px; color: var(--t); flex: 1;
}
.sb-brand-btn .sb-name span { color: var(--brand); }
.sb-brand-btn .sb-caret {
  width: 12px; height: 12px;
  transition: transform 0.2s;
  color: var(--m);
}
.sb-brand-btn.open .sb-caret { transform: rotate(180deg); }

/* ---------- 品牌矩阵下拉 ---------- */
.sb-brand-switcher {
  display: none;
  position: absolute;
  top: 100%;
  left: 12px;
  right: 12px;
  background: var(--card);
  border: 1px solid var(--line-h);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  margin-top: 6px;
  z-index: 200;
}
.sb-brand-switcher.show { display: block; }
.sb-brand-switcher .sb-site-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px;
  background: none; border: none; border-radius: var(--r-sm);
  text-align: left; cursor: pointer; color: var(--t);
  transition: background 0.15s;
}
.sb-brand-switcher .sb-site-item:hover { background: var(--brand-l); }
.sb-brand-switcher .sb-site-item.current {
  background: var(--brand-l); color: var(--brand-text); font-weight: 700;
}
.sb-brand-switcher .sb-site-item .sb-site-icon { font-size: 22px; }
.sb-brand-switcher .sb-site-item .sb-site-name { font-weight: 700; font-size: 14px; }
.sb-brand-switcher .sb-site-item .sb-site-desc { font-size: 12px; color: var(--m); }

/* ---------- 侧栏主体 ---------- */
.sb-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 16px;
  -webkit-overflow-scrolling: touch;
}
.sb-body::-webkit-scrollbar { width: 4px; }
.sb-body::-webkit-scrollbar-thumb { background: var(--line-h); border-radius: 2px; }

/* 分组标题 */
.sb-group { margin-bottom: 4px; margin-top: 10px; }
.sb-group-title {
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--m); padding: 14px 16px 8px;
}

/* 链接项 */
.sb-link {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 16px;
  background: none; border: none; border-radius: var(--r-sm);
  color: var(--m); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all 0.15s; text-align: left;
}
.sb-link:hover { background: var(--brand-l); color: var(--brand-text); }
.sb-link.active { background: var(--brand-l); color: var(--brand-text); font-weight: 700; }
.sb-link .sb-icon { font-size: 18px; width: 22px; text-align: center; }
.sb-link.sb-external { position: relative; }
.sb-link.sb-external::after {
  content: "\2197"; font-size: 11px; color: var(--m); margin-left: auto;
}

/* ---------- 侧栏底部 ---------- */
.sb-footer {
  border-top: 1px solid var(--line);
  padding: 12px 8px;
  /* iOS 安全区：底部 */
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}
.sb-lang-inline { margin-bottom: 8px; }

/* ---------- 移动端汉堡按钮（三线动画） ---------- */
.sb-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 40px; height: 40px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  cursor: pointer;
  padding: 0;
  transition: background 0.15s;
}
.sb-toggle:hover { background: var(--brand-l); }
.sb-toggle:active { transform: scale(0.95); }
/* iOS 安全区：汉堡按钮也避让刘海 */
@supports (padding-top: env(safe-area-inset-top)) {
  .sb-toggle { top: calc(12px + env(safe-area-inset-top, 0px)); }
}

/* 三线 bar 容器 */
.sb-toggle-bars {
  display: flex; flex-direction: column; gap: 4px;
  width: 20px;
}
.sb-toggle-bars span {
  display: block; height: 2px; background: var(--t); border-radius: 2px;
  transition: transform 0.25s, opacity 0.2s;
  transform-origin: center;
}
/* open 状态：三线变 X */
.sb-toggle.open .sb-toggle-bars span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
.sb-toggle.open .sb-toggle-bars span:nth-child(2) {
  opacity: 0;
}
.sb-toggle.open .sb-toggle-bars span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

/* ---------- 移动端遮罩层（真实 DOM，不是 ::after） ---------- */
.sb-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.25s;
}
body.sb-open .sb-mask {
  display: block;
  opacity: 1;
}
/* 打开时禁止 body 滚动 */
body.sb-open { overflow: hidden; }

/* ---------- 边缘滑动触摸区 ---------- */
.sb-edge-handle {
  display: none;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 12px;
  z-index: 89;
}

/* ---------- 响应式 ---------- */
/* ---------- 内建语言下拉 ---------- */
.sb-lang {
  position: relative;
}
.sb-lang-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  background: none;
  border: none;
  border-radius: var(--r-sm);
  color: var(--m);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}
.sb-lang-btn:hover {
  background: var(--brand-l);
  color: var(--brand-text);
}
.sb-lang-btn .sb-caret {
  margin-left: auto;
  width: 12px; height: 12px;
  transition: transform 0.2s;
}
.sb-lang-btn.open .sb-caret {
  transform: rotate(180deg);
}
.sb-lang-menu {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 4px;
  right: 4px;
  margin-bottom: 6px;
  background: var(--card);
  border: 1px solid var(--line-h);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 300;
}
.sb-lang-menu.open {
  display: block;
  animation: sb-lang-fade 0.15s ease-out;
}
@keyframes sb-lang-fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.sb-lang-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  background: none;
  border: none;
  border-radius: var(--r-sm);
  text-align: left;
  cursor: pointer;
  color: var(--t);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.12s;
}
.sb-lang-item:hover {
  background: var(--brand-l);
}
.sb-lang-item.active {
  background: var(--brand-l);
  color: var(--brand-text);
  font-weight: 700;
}
.sb-lang-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 22px;
  font-size: 11px;
  font-weight: 800;
  border-radius: 4px;
  background: var(--line);
  color: var(--t);
  flex-shrink: 0;
}
.sb-lang-item.active .sb-lang-code {
  background: var(--brand-700, var(--brand));  /* v3: 白字安全值 */
  color: #fff;
}
@media (max-width: 760px) {
  /* 移动端侧栏：85vw + max 300px + min 260px */
  .sb {
    width: min(85vw, 300px);
    max-width: 300px;
    min-width: 260px;
    transform: translateX(-100%);
    box-shadow: none;
    /* iOS 安全区：顶部留刘海空间 */
    padding-top: env(safe-area-inset-top, 0px);
  }
  .sb.open {
    transform: translateX(0);
    box-shadow: 8px 0 24px rgba(0,0,0,0.15);
  }
  .sb-main { margin-left: 0; }
  .sb-toggle { display: flex; }
  .sb-edge-handle { display: block; }

  /* 汉堡按钮在 iPad mini 等稍宽屏也显示 */
  .sb-brand { padding: 14px 14px 10px; }
  .sb-group-title { padding: 12px 14px 6px; }
  .sb-link { padding: 8px 14px; font-size: 13px; }
}

/* 平板过渡区：侧栏收窄 + 汉堡可选 */
@media (min-width: 761px) and (max-width: 960px) {
  .sb { width: 180px; }
  :root { --sidebar-w: 180px; }
}

/* 小屏手机进一步压缩 */
@media (max-width: 380px) {
  .sb { width: 88vw; min-width: auto; }
  .sb-toggle { width: 36px; height: 36px; top: 10px; left: 10px; }
}


/* ========== 方案 A: 桌面用顶栏承载全局导航, 侧栏仅作移动端抽屉 ========== */
@media (min-width: 821px) {
  .sb { display: none !important; }
  .sb-main { margin-left: 0 !important; }
  .sb-toggle, .sb-edge-handle, .sb-mask { display: none !important; }
}
@media (max-width: 820px) {
  /* 语言切换移到抽屉顶部, 打开即可见 */
  .sb-footer { order: -1; border-top: 0; border-bottom: 1px solid var(--line, #e5e7eb); }
}

/* 方案 A 修正: .layout(display:flex) 内 .sb-main 需要撑满主区 */
.sb-main { flex: 1 1 auto; min-width: 0; width: 100%; }
@media (max-width: 820px) {
  /* 抽屉/窄栏顶部让位给 64px 吸顶顶栏, 否则首个区块被顶栏遮住 */
  .sb { padding-top: calc(env(safe-area-inset-top, 0px) + 64px); }
}