/* base.css — 重置、排版、应用外壳、响应式布局、通用工具类
 * 约束：不写组件外观（去 components.css）；不写内联样式。
 */

*,
*::before,
*::after { box-sizing: border-box; }

html {
  /* 先 hidden 再覆盖为 clip：旧浏览器退回 hidden，新浏览器避免 sticky 失效 */
  overflow-x: hidden;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p, figure, blockquote, dl, dd { margin: 0; }
h1, h2, h3, h4 { line-height: 1.25; font-weight: 600; }
h1 { font-size: clamp(24px, 3vw, 32px); }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }

ul, ol { margin: 0; padding-left: 1.25em; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* [hidden] 压不住 display:flex/grid，必须强制 */
[hidden] { display: none !important; }

::selection {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
}

/* 全局焦点环：禁止 outline:none */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-s);
}

/* 数字等宽：刷新时不左右抖动 */
.num,
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- 跳转主内容 ---------- */
.skip-link {
  position: fixed;
  top: var(--sp-2);
  left: var(--sp-2);
  z-index: 100;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-s);
  background: var(--bg-elev-1);
  border: 1px solid var(--line-strong);
  color: var(--text);
  transform: translateY(-200%);
  transition: transform var(--dur-fast) var(--ease-io);
}
.skip-link:focus-visible { transform: translateY(0); }

/* ---------- 应用外壳 ---------- */
.shell { min-height: 100dvh; }
.main { min-width: 0; }

.content {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-4) calc(84px + env(safe-area-inset-bottom));
  min-width: 0;
}

/* 桌面：左侧固定导航 220px */
@media (min-width: 1024px) {
  .shell {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
  }
  .sidebar {
    position: sticky;
    top: 0;
    height: 100dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-right: 1px solid var(--line);
    padding: var(--sp-5) var(--sp-4);
  }
  .content {
    padding: var(--sp-6) var(--sp-6) var(--sp-6);
  }
  .topbar { display: none; }
  .chipnav { display: none; }
  .tabbar { display: none; }
}

/* 平板：顶部横向导航，无侧栏 */
@media (min-width: 768px) and (max-width: 1023px) {
  .sidebar { display: none; }
}

/* 手机：底部 tab 栏 */
@media (max-width: 767px) {
  .sidebar { display: none; }
  .content {
    padding: var(--sp-4) var(--sp-3) calc(72px + env(safe-area-inset-bottom));
  }
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 56px;
  padding: 0 var(--sp-4);
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 600;
  letter-spacing: .01em;
  min-width: 0;
}
.topbar__brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__actions { margin-left: auto; display: flex; gap: var(--sp-2); }

/* 平板横向导航条 */
.chipnav {
  position: sticky;
  top: 56px;
  z-index: 19;
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.chipnav::-webkit-scrollbar { display: none; }

/* ---------- 底部 tab 栏 ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
  padding: var(--sp-1) 0;
  color: var(--text-mute);
  font-size: 12px;
  touch-action: manipulation;
  user-select: none;
}
.tabbar__item[aria-current="page"] { color: var(--accent); }
.tabbar__item:hover { text-decoration: none; }

/* ---------- 侧栏 ---------- */
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-2) var(--sp-5);
  font-size: 16px;
  font-weight: 600;
}
.sidebar__group {
  margin: var(--sp-4) 0 var(--sp-2);
  padding: 0 var(--sp-2);
  font-size: 12px;
  color: var(--text-mute);
}
.sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 36px;
  padding: 0 var(--sp-2);
  border-radius: var(--radius-s);
  color: var(--text-dim);
  font-size: 13px;
}
.sidebar__link:hover {
  background: var(--bg-elev-1);
  color: var(--text);
  text-decoration: none;
}
.sidebar__link[aria-current="page"] {
  background: var(--bg-elev-2);
  color: var(--text);
}
.sidebar__foot {
  margin-top: auto;
  padding: var(--sp-4) var(--sp-2) 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--text-mute);
}

/* ---------- 排版与工具 ---------- */
.fs-12 { font-size: 12px; }
.fs-13 { font-size: 13px; }
.fs-14 { font-size: 14px; }
.fs-16 { font-size: 16px; }
.fs-20 { font-size: 20px; }
.fs-24 { font-size: 24px; }
.fs-32 { font-size: 32px; }
.dim  { color: var(--text-dim); }
.mute { color: var(--text-mute); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.strong { font-weight: 600; }

.row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; min-width: 0; }
.row--between { justify-content: space-between; }
.stack { display: grid; gap: var(--sp-4); min-width: 0; }
.stack--sm { gap: var(--sp-2); }
.cluster { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; min-width: 0; }

.grid-2 { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); align-items: start; min-width: 0; }
.grid-3 { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); min-width: 0; }

.stack > *, .row > *, .grid-2 > *, .grid-3 > * { min-width: 0; }

.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wrap-anywhere { overflow-wrap: anywhere; }

.divider { height: 1px; background: var(--line); border: 0; margin: var(--sp-4) 0; }

.mt-1 { margin-top: var(--sp-1); }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }

/* 页面区块（预览页与后续页面共用） */
.section { scroll-margin-top: 84px; }
.section + .section { margin-top: var(--sp-6); }
.section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
}
.section__title { font-size: 20px; font-weight: 600; }
.section__note { font-size: 13px; color: var(--text-mute); }
.kicker {
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-mute);
}

/* 供骨架屏与异步内容使用 */
.is-busy { pointer-events: none; }

/* ---------- 无障碍 ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 动效降级 ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* 手机端：标题独占一行，说明换行显示，避免与标题挤在一行被裁 */
@media (max-width: 767px) {
  .section__note { flex: 1 0 100%; }
}

/* 移动端输入不触发 iOS 自动放大 */
@media (max-width: 767px) {
  input, select, textarea { font-size: 16px; }
}

/* ---------- 断点覆盖（顺序敏感，勿上移） ----------
 * .topbar / .chipnav / .tabbar 的 display 在本文件后段才声明，
 * 若把隐藏规则写在上面的断点块里，会被后面的 display:flex/grid 覆盖。
 * 这里放在最后，保证「桌面无顶栏 / 平板无底栏 / 手机无目录条」。
 * 不要优化成把这些规则挪回上方。
 */
@media (min-width: 1024px) {
  .topbar, .chipnav, .tabbar { display: none; }
  .content { padding-bottom: var(--sp-6); }
}
@media (min-width: 768px) {
  .tabbar { display: none; }
}
@media (max-width: 1023px) {
  .sidebar { display: none; }
}
@media (max-width: 767px) {
  .chipnav { display: none; }
}
