/* 布局层：登录页、应用骨架、侧栏、顶栏、视图容器、响应式。
   禁止出现 hex / rgb 字面量。 */

/* ============================================================
   登录 / 注册
   ============================================================ */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--sp-5);
  background: var(--canvas);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: var(--sp-6);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xl);
  background: var(--surface-1);
  box-shadow: var(--shadow-2);
  animation: rise var(--dur-slow) var(--ease-out);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}
.auth-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px; height: 46px;
  border-radius: var(--radius-lg);
  background: var(--primary-soft);
  color: var(--primary);
}
.auth-title { font-size: var(--fs-h1); }
.auth-sub { margin-top: 2px; font-size: var(--fs-xs); color: var(--ink-muted); }

.seg {
  display: flex;
  gap: var(--sp-1);
  padding: var(--sp-1);
  margin-bottom: var(--sp-5);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.seg-btn {
  flex: 1;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.seg-btn.is-active { background: var(--surface-1); color: var(--ink); box-shadow: var(--shadow-1); }

.auth-form { display: flex; flex-direction: column; gap: var(--sp-4); }
/* 登录卡内的字段标签比正文更淡一档,避免与输入内容抢视觉 */
.auth-form .field-label { letter-spacing: .01em; }

.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field-label { font-size: var(--fs-xs); font-weight: 500; color: var(--ink-muted); }
.field-wrap { position: relative; display: block; }
.field-icon {
  position: absolute;
  left: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  color: var(--ink-subtle);
  pointer-events: none;
}
.field-wrap .input {
  /* 左侧留出图标位置,高度略高于普通输入框,配合登录卡的留白 */
  height: 42px;
  padding-left: 38px;
  font-size: var(--fs-body);
}
/* 右侧带操作按钮(例如显示密码)时,避免文字被按钮压住 */
.field-wrap-action .input { padding-right: 42px; }
.field-action {
  position: absolute;
  right: var(--sp-2);
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-subtle);
  cursor: pointer;
}
.field-action:hover { color: var(--ink); background: var(--surface-2); }

.auth-hint { min-height: 18px; font-size: var(--fs-xs); color: var(--danger); }
.auth-hint.ok { color: var(--ok); }
.auth-foot {
  margin-top: var(--sp-5);
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--ink-subtle);
}
/* 联系管理员:用主色强调,与普通说明文字区分 */
.auth-link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid var(--primary-soft);
  padding-bottom: 1px;
}
.auth-link:hover { color: var(--primary-hover); border-bottom-color: var(--primary); }
/* 协议入口是 button 而不是 a:它要弹窗而不是跳转。
   用 button 保留键盘焦点与回车触发,比给 a 加 onclick 更无障碍友好。 */
.auth-link-btn {
  background: none;
  border: 0;
  border-bottom: 1px dashed transparent;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

/* ============================================================
   应用骨架
   ============================================================ */
.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------------- 侧栏(两层) ----------------
   批次 3 起侧栏是两层:
     .side-rail   一级 Tab,窄栏,图标 + 文字
     .side-panel  二级项 + 用户卡片 + 最近对话 + 底部工具行
   一级只有 6 项(5 Tab + 管理),二级随 Tab 变化。
   改造前是单层平铺 21 项,手机上要滚两屏。 */
.sidebar {
  display: flex;
  flex-direction: row;
  width: calc(var(--rail-w) + var(--sidebar-w));
  flex: 0 0 calc(var(--rail-w) + var(--sidebar-w));
  border-right: 1px solid var(--hairline);
  background: var(--glass-surface);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  transition: transform var(--dur) var(--ease);
}

/* 一级:Tab 栏 */
.side-rail {
  display: flex;
  flex-direction: column;
  width: var(--rail-w);
  flex: 0 0 var(--rail-w);
  border-right: 1px solid var(--hairline);
  background: var(--surface-3);
}
.rail-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--topbar-h);
  flex: 0 0 auto;
  border-bottom: 1px solid var(--hairline);
}
.rail-list {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-2) var(--sp-1) 0;
}
/* 管理员入口紧跟在「我的」下方,与 5 个 Tab 同列
   (用户 2026-09-04 验收批次 3 时要求;原本在侧栏底部,离得太远不好找)。
   上方留一条细线与一点间距 —— 它只有管理员可见,不属于日常 5 个 Tab。 */
.rail-admin {
  flex: 0 0 auto;
  margin: var(--sp-2) var(--sp-1) 0;
  padding-top: var(--sp-2);
  border-top: 1px solid var(--hairline);
}
/* 撑开剩余高度,把 Tab 顶到上方。
   不能让 .rail-list 自己 flex:1 —— 那样 6 个 Tab 会被拉散到整列高度。
   一级栏项数少(最多 6 个),不需要滚动,所以这里用占位而不是 overflow。 */
.rail-fill { flex: 1 1 auto; min-height: 0; }
.rail-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  padding: var(--sp-2) 2px;
  border: 0;
  border-radius: var(--nav-radius);
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.rail-item > i { display: inline-flex; color: var(--ink-subtle); }
.rail-label {
  font-size: var(--fs-xxs);
  line-height: 1.2;
  letter-spacing: var(--track-body);
}
.rail-item:hover { background: var(--surface-2); color: var(--ink); }
.rail-item:hover > i { color: var(--ink-muted); }
.rail-item.is-active { background: var(--primary-soft); color: var(--primary); font-weight: var(--fw-mid); }
.rail-item.is-active > i { color: var(--primary); }
/* Tab 级红点:把该 Tab 下的未读合并成一个点,手机端底部 Tab 栏(批次 4)复用 */
.rail-dot {
  position: absolute;
  top: 6px; right: 8px;
  width: 7px; height: 7px;
  border-radius: var(--radius-pill);
  background: var(--danger);
}

/* 二级:当前 Tab 的子项 */
.side-panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  height: var(--topbar-h);
  /* 站点图标移到一级栏的 .rail-brand 了,这里只剩站点名 */
  padding: 0 var(--sp-2) 0 var(--sp-3);
  border-bottom: 1px solid var(--hairline);
}
.side-brand { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.side-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: var(--primary);
  flex: 0 0 auto;
}
.side-brand-text { display: flex; flex-direction: column; min-width: 0; }
.side-brand-text strong {
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-brand-text small { font-size: var(--fs-xxs); color: var(--ink-subtle); }
.side-close { display: none; }

.side-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: var(--sp-3) var(--sp-2);
}

.nav-group-label {
  padding: var(--sp-3) var(--sp-2) var(--sp-1);
  font-size: var(--fs-xxs);
  font-weight: 600;
  color: var(--ink-subtle);
  letter-spacing: .04em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: 8px var(--sp-2);
  margin-bottom: 2px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink-body);
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-item > i { display: inline-flex; color: var(--ink-subtle); flex: 0 0 auto; }
.nav-item > span { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item:hover { background: var(--surface-3); color: var(--ink); }
.nav-item:hover > i { color: var(--ink-muted); }
.nav-item.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.nav-item.is-active > i { color: var(--primary); }

.nav-count {
  min-width: 20px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--surface-4);
  color: var(--ink-muted);
  font-size: var(--fs-xxs);
  font-weight: 500;
  text-align: center;
}
.nav-item.is-active .nav-count { background: var(--primary); color: var(--on-primary); }
.nav-count-alert:not([hidden]) { background: var(--warn-soft); color: var(--warn); }
.nav-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--warn);
  flex: 0 0 auto;
}

/* 最近对话(置顶显示在导航上方) */
.side-recent {
  flex: 0 0 auto;
  max-height: 42%;
  display: flex;
  flex-direction: column;
  padding: var(--sp-2);
  border-bottom: 1px solid var(--hairline);
}
.side-recent-top { border-top: 0; }
.side-recent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-1) var(--sp-2);
  font-size: var(--fs-xxs);
  font-weight: 600;
  color: var(--ink-subtle);
}
.recent-list { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.recent-item {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  width: 100%;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
}
.recent-item:hover { background: var(--surface-3); color: var(--ink); }
.recent-item.is-active { background: var(--surface-1); color: var(--ink); }
.recent-open {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px var(--sp-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  font-size: var(--fs-xs);
  text-align: left;
  cursor: pointer;
}
.recent-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-item .icon-btn { opacity: 0; flex: 0 0 auto; margin-right: 2px; }
.recent-item:hover .icon-btn,
.recent-item:focus-within .icon-btn { opacity: 1; }
.recent-more {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  margin-top: var(--sp-1);
  padding: 5px var(--sp-2);
  border: 1px dashed var(--hairline-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-subtle);
  font-size: var(--fs-xxs);
  cursor: pointer;
}
.recent-more:hover { color: var(--primary); border-color: var(--primary); }
.recent-more.is-open i { transform: rotate(180deg); }
.recent-more i { display: inline-flex; transition: transform var(--dur-fast) var(--ease); }

/* 侧栏底部 */
.side-foot { flex: 0 0 auto; border-top: 1px solid var(--hairline); padding: var(--sp-2); }
.user-row { display: flex; align-items: center; gap: var(--sp-2); }
.user-meta { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.user-meta strong {
  font-size: var(--fs-xs);
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* 接口状态是一行短文案,必须单行。
   不加 nowrap 的话在窄面板里会逐字换行成竖排 ——
   批次 3 上线后就出现过这个问题(当时可用宽度只剩 18px)。
   现在去掉头像与改密码按钮后有 100px,足够 12px × 6 字;
   万一主题字号更大,省略号兜底。 */
.user-meta small {
  font-size: var(--fs-xxs);
  color: var(--ink-subtle);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-meta small.warn { color: var(--warn); }
.user-meta small.ok { color: var(--ok); }

.sidebar-scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 29;
}

/* ---------------- 主区 ---------------- */
.main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--canvas);
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: var(--topbar-h);
  flex: 0 0 auto;
  padding: 0 var(--sp-5);
  border-bottom: 1px solid var(--hairline);
  background: var(--canvas);
}
.topbar-menu { display: none; }
.topbar-title { flex: 1 1 auto; min-width: 0; }
.topbar-title h2 {
  font-size: var(--fs-ui-title);
  line-height: var(--lh-tight);
  /* 必须单行 + 省略号。原来是 --fs-h2(apple 下 24px),
     顶栏只有一行高度,长标题会被逐字换行成竖排 —— 用户实际遇到过。 */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.topbar-title p {
  font-size: var(--fs-xxs);
  line-height: var(--lh-tight);
  color: var(--ink-subtle);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-actions { display: flex; align-items: center; gap: var(--sp-2); flex: 0 0 auto; min-width: 0; max-width: 100%; }
/* 顶栏内的按钮降一档。
   .icon-btn 是全站通用的 34px,表单、卡片、消息工具条都用它 ——
   不能直接改小,只在顶栏范围内覆盖。
   28px 是 .icon-btn-sm 的尺寸,与既有档位对齐,不新造数值。
   触屏设备下由 (pointer: coarse) 那条规则提回 40px,不影响点得中。 */
.topbar .icon-btn { width: 28px; height: 28px; }
.topbar .btn {
  height: 28px;
  padding: 0 var(--sp-3);
  font-size: var(--fs-xs);
}
.topbar .btn-sm { height: 26px; }

.view-root {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  /* iOS 的惯性滚动。现代 iOS Safari 默认已经是 touch,但旧版(以及部分
     国内内核浏览器)在 overflow:auto 容器里会退化成「一格一格」的生硬滚动。
     桌面端无副作用 —— 该属性只被移动端 WebKit 识别。 */
  -webkit-overflow-scrolling: touch;
}

.view {
  max-width: var(--view-max);
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-5) var(--sp-8);
  animation: fadeIn var(--dur) var(--ease-out);
}
.view-full { max-width: none; padding: 0; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}
.view-head-text h3 { font-size: var(--fs-ui-title); }
.view-head-text p { margin-top: 2px; font-size: var(--fs-xs); color: var(--ink-muted); }
.view-head-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* 网格 */
.grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.grid-stats { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-2); }
.row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }

/* ============================================================
   底部 Tab 栏与二级抽屉(手机端外壳)

   桌面端默认全部隐藏。≤1023px 时 Tab 栏出现、两层侧栏收起。
   为什么是 1023 而不是 767:768~1023 的平板竖屏,双层侧栏 252px
   会把内容区挤到不足 500px,底部 Tab 更合适。
   ============================================================ */
.tabbar { display: none; }
.nav-sheet { display: none; }
.sheet-scrim { display: none; }
/* 悬浮主操作按钮只在手机端出现:桌面端顶栏有足够横向空间放文字按钮,
   再叠一个悬浮圆钮会与顶栏按钮重复。 */
.fab { display: none; }

/* ============================================================
   响应式：768 / 1024 / 1440
   ============================================================ */
@media (max-width: 1023px) {
  /* 内容区底部要给 Tab 栏 + 安全区留位,否则最后一项被遮住。
     用 max() 包 env():非刘海设备上 env() 为 0,直接相加会让 Tab 栏贴边。 */
  .view {
    padding: var(--sp-4) var(--sp-4)
             calc(var(--tabbar-h) + var(--sp-7) + max(0px, env(safe-area-inset-bottom)));
    /* 横屏时内容也要避让左右刘海 —— 改造前只有 .topbar 让了,
       正文与卡片仍会被挖角遮住一小块(设计稿 03 第 1 节)。
       长写法放在 shorthand 之后覆盖左右两位:shorthand 那一行必须保留,
       它带着 --tabbar-h 的底部留白。 */
    padding-right: max(var(--sp-4), env(safe-area-inset-right));
    padding-left: max(var(--sp-4), env(safe-area-inset-left));
  }
  /* 窄屏隐藏:同一动作在手机端换成悬浮按钮时,顶栏那一个要收起,
     否则同屏出现两个「新建」。 */
  .hide-narrow { display: none; }
  /* 顶栏避让刘海 / 灵动岛。横屏时左右也要让 */
  /* 四值简写是 top right bottom left —— 右位必须用 inset-right、
     左位必须用 inset-left。写反的话横屏时避让方向互换,
     刘海那一侧反而贴边。 */
  .topbar {
    padding-top: env(safe-area-inset-top);
    padding-right: max(var(--sp-4), env(safe-area-inset-right));
    padding-bottom: 0;
    padding-left: max(var(--sp-4), env(safe-area-inset-left));
  }

  /* 两层侧栏在此以下不再常驻,也不再滑出 —— 一级由底部 Tab 承担,
     二级由顶栏汉堡打开的抽屉承担。 */
  .sidebar { display: none; }
  .sidebar-scrim { display: none; }
  .topbar-menu { display: inline-flex; }

  /* ---------------- 底部 Tab 栏 ---------------- */
  .tabbar {
    position: fixed;
    inset: auto 0 0 0;
    /* 25:低于 sidebar-scrim(29) 与 sidebar(30),高于内容。
       所有弹层都在其上:modal 100 / popover 120 / dropdown 130 / toast 150。 */
    z-index: 25;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    padding-bottom: env(safe-area-inset-bottom);
    /* 0.48.0 移除磨砂:改造前是 --glass-surface(半透明) + backdrop-filter。
       现在是实色 —— 底栏与主区的色差 + 上边框已足够表达层级,
       而半透明 + 模糊是低端安卓的主要掉帧源。 */
    background: var(--glass-surface);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border-top: 1px solid var(--hairline);
    transition: transform var(--dur) var(--ease);
  }
  /* 隐藏用 transform 而非 display —— 要能滑出滑入。
     110% 而不是 100%:阴影与边框也要移出视口。 */
  .tabbar.is-hidden { transform: translateY(110%); }

  .tabitem {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: var(--tabbar-h);
    padding: 0 2px;
    border: 0;
    background: transparent;
    color: var(--ink-subtle);
    font-size: var(--fs-xxs);
    cursor: pointer;
    transition: color var(--dur-fast) var(--ease);
    -webkit-tap-highlight-color: transparent;
  }
  .tabitem-icon { display: inline-flex; }
  .tabitem-label { line-height: 1.1; }
  .tabitem.is-active { color: var(--primary); }
  .tabitem.is-active .tabitem-icon { animation: tabPop var(--dur-slow) var(--ease-spring); }
  /* 顶部指示条。scaleX 而非 width:变换不触发重排 */
  .tabitem::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 22px;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--primary);
    transform: translateX(-50%) scaleX(0);
    transition: transform var(--dur) var(--ease-out);
  }
  .tabitem.is-active::before { transform: translateX(-50%) scaleX(1); }

  /* Tab 级角标。合并该 Tab 下所有 alert 类子项的未读数 */
  .tabitem-dot {
    position: absolute;
    top: 6px;
    left: 50%;
    margin-left: 6px;
    min-width: 8px;
    height: 8px;
    border-radius: var(--radius-pill);
    background: var(--danger);
  }
  /* 数字角标。实心 danger 底 + --on-primary 文字,沿用 .toast-err 的既有惯例
     (components.css 里 .toast 基类 color:--on-primary,.toast-err 背景 --danger)。

     不新造 --on-danger:新增语义位要五套主题各补日夜两组,本批不扩 L1。

     已知不足:--on-primary 并非始终为白 —— supabase 日间是 #171717,
     四套的夜间组也都是深色,配红底对比度偏低(约 3.5:1)。
     这是 .toast-err 早就存在的同一问题,不是本批引入;
     若要根治需新增 --on-danger 语义位并补五套主题,留到第三期清理冗余时一并做。 */
  .tabitem-dot.has-num {
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
    color: var(--on-primary);
  }

  /* ---------------- 悬浮主操作按钮 ---------------- */
  /* 位置:右下角,坐在 Tab 栏正上方。
     bottom 要同时避开 Tab 栏、安全区与键盘 —— 三者都可能同时存在
     (例如 iPhone 竖屏 + 键盘弹出)。--kb-height 由 app.js 写入,无键盘时为 0。 */
  .fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: max(var(--sp-4), env(safe-area-inset-right));
    bottom: calc(var(--tabbar-h) + var(--sp-4) + var(--kb-height, 0px)
                 + max(0px, env(safe-area-inset-bottom)));
    /* 24:高于内容、低于 Tab 栏(25)—— 滑到底部时它不该盖住 Tab 项。 */
    z-index: 24;
    width: 52px;
    height: 52px;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--primary);
    color: var(--on-primary);
    box-shadow: var(--shadow-2);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
  }
  .fab:active { transform: scale(var(--press)); background: var(--primary-active); }
  /* 进入会话这类深层态时与 Tab 栏一起滑出。用 transform 而非 display:
     display 切换没有过渡,会「啪」地消失。 */
  .fab.is-hidden { transform: translateY(200%); }

  /* ---------------- 二级菜单抽屉 ---------------- */
  .sheet-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 29;
    background: var(--scrim);
  }
  .nav-sheet {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 30;
    max-height: 72vh;
    padding-bottom: max(var(--sp-2), env(safe-area-inset-bottom));
    background: var(--surface-1);
    border-top: 1px solid var(--hairline);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow-3);
    animation: sheetRise var(--dur) var(--ease-spring);
  }
  /* 顶部小横条:提示这是可下拉关闭的抽屉,是「像 App」的关键细节之一 */
  .nav-sheet-grip {
    flex: 0 0 auto;
    width: 36px;
    height: 4px;
    margin: var(--sp-2) auto 0;
    border-radius: var(--radius-pill);
    background: var(--hairline-strong, var(--hairline));
  }
  .nav-sheet-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3) var(--sp-1);
  }
  .nav-sheet-title { flex: 1 1 auto; font-size: var(--fs-sm); color: var(--ink); }
  .nav-sheet-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    /* 抽屉内滚动不穿透到背后页面 */
    overscroll-behavior: contain;
    padding: var(--sp-1) var(--sp-2) var(--sp-2);
  }
  .sheet-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    width: 100%;
    min-height: 48px;
    padding: 0 var(--sp-3);
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink);
    font-size: var(--fs-sm);
    text-align: left;
    cursor: pointer;
  }
  .sheet-item:active { background: var(--surface-3); }
  .sheet-item.is-active { background: var(--primary-soft); color: var(--primary); }
  .sheet-item-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .sheet-item-count {
    flex: 0 0 auto;
    font-size: var(--fs-xxs);
    color: var(--ink-subtle);
    font-variant-numeric: tabular-nums;
  }
  .sheet-item-check { flex: 0 0 auto; display: inline-flex; color: var(--primary); }
  .sheet-group-label {
    padding: var(--sp-3) var(--sp-3) var(--sp-1);
    font-size: var(--fs-xxs);
    color: var(--ink-subtle);
  }
  .sheet-divider { height: 1px; margin: var(--sp-2) var(--sp-3); background: var(--hairline); }

  .topbar.topbar-multiline { height: auto; min-height: var(--topbar-h); flex-wrap: wrap; row-gap: var(--sp-2); padding-bottom: var(--sp-2); }
  .topbar-multiline .topbar-title { min-height: 40px; display: flex; flex-direction: column; justify-content: center; }
  .topbar-multiline .topbar-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); flex: 1 0 100%; width: 100%; }
  .topbar-multiline .topbar-actions .btn { min-width: 0; min-height: 36px; height: auto; padding: var(--sp-2); white-space: normal; font-size: var(--fs-xs); }
  .topbar-multiline .btn-label { min-width: 0; overflow-wrap: anywhere; }
}

@keyframes sheetRise { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes tabPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.22) translateY(-2px); }
  100% { transform: scale(1); }
}

/* 键盘弹出时收起 Tab 栏。
   不收起的话:虚拟键盘把视口压矮,fixed 的 Tab 栏会浮在键盘上方挡住输入框。
   --kb-height 由 app.js 的 visualViewport 监听写入。 */
html[data-keyboard='open'] .tabbar { transform: translateY(110%); }
html[data-keyboard='open'] .view { padding-bottom: var(--sp-7); }
/* 键盘弹出时悬浮按钮也收起:它会浮在键盘上方挡住输入区,
   而此刻用户正在打字,「新建」不是他要做的事。 */
html[data-keyboard='open'] .fab { transform: translateY(200%); }

/* 触屏设备(含平板横屏,不只看屏宽):触控目标放大到 44px。
   桌面端保持紧凑,不被牺牲。 */
@media (hover: none) and (pointer: coarse) {
  .icon-btn { width: 44px; height: 44px; }
  .icon-btn-sm { width: 40px; height: 40px; }
  /* 顶栏按钮在桌面端降到 28px(顶栏只有 48px 高),但触屏上必须提回来 ——
     媒体查询不提升特异度,`.topbar .icon-btn`(0,2,0) 会压过这里的
     `.icon-btn`(0,1,0),所以必须用同样的选择器才能覆盖。
     40px 而非 44px:顶栏 48px 高,44px 会顶满没有余量。 */
  .topbar .icon-btn { width: 40px; height: 40px; }
  .topbar .btn { height: 36px; }
}

@media (max-width: 767px) {
  /* 侧栏相关规则已随批次 4 移除 —— ≤1023px 时侧栏整体 display:none,
     不再滑出,所以 .sidebar.open / .side-close / .side-user 这些
     窄屏微调都失去意义。一级走底部 Tab,二级走抽屉。 */
  .form-grid.two { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
}

@media (min-width: 1280px) {
  :root { --view-max: 1200px; }
}

/* 窄屏多动作顶栏:保留全部文字按钮,独立换行,不挤掉标题或第三个按钮。 */
.view-mount[data-view='apiSettings'] > .view,
.view-mount[data-view='appearance'] > .view,
.view-mount[data-view='security'] > .view {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}
