/* =========================================================================
   SVS 病理图像查看器 —— Apple HIG / macOS Sonoma 视觉语言
   ========================================================================= */

:root {
  /* 字体 */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, "Courier New", monospace;

  /* 颜色 */
  --accent: #007AFF;
  --accent-hover: #0062CC;
  --accent-fill: rgba(0, 122, 255, 0.12);
  --bg: #f5f5f7;
  --sidebar-bg: rgba(242, 242, 247, 0.85);
  --toolbar-bg: rgba(255, 255, 255, 0.85);
  --text: #1d1d1f;
  --text-2: #86868b;
  --text-3: #a1a1a6;
  --separator: rgba(0, 0, 0, 0.08);
  --separator-strong: rgba(0, 0, 0, 0.12);
  --hover: rgba(0, 0, 0, 0.05);
  --hover-strong: rgba(0, 0, 0, 0.08);
  --danger: #FF3B30;
  --danger-tint: rgba(255, 59, 48, 0.1);
  --seg-bg: #e9e9eb;
  --viewer-bg: #262a30;

  /* 圆角 */
  --r-row: 8px;
  --r-btn: 7px;
  --r-panel: 12px;
  --r-pill: 10px;

  /* 阴影 */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-panel: 0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-float: 0 8px 24px rgba(0, 0, 0, 0.15);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

button {
  font-family: inherit;
}

/* =========================================================================
   统一标题栏 + 工具栏（unified titlebar-toolbar）
   ========================================================================= */
#app-header {
  height: 52px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 0.5px solid var(--separator);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  flex-shrink: 0;
  z-index: 10;
}

.title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 0 1 auto; /* 可缩不可涨：不与工具栏抢空间 */
}

.header-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.2px;
  flex-shrink: 0; /* 品牌名不收缩 */
}

/* 装饰性副标题与分隔符一律不显示（宽屏也不占标题栏宽度），品牌与徽标靠 gap 分隔 */
.title-sep,
.header-subtitle { display: none; }

/* Beta 状态徽标（§3.4）：品牌区常驻；不可点击、可聚焦提示产品阶段。
   切片名不再常驻品牌区（document.title / 侧栏选中行 / 面板标题仍可读）。 */
.beta-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: var(--accent);
  border: 1px solid rgba(0, 122, 255, 0.35);
  border-radius: 6px;
  padding: 1px 6px;
  line-height: 1.4;
  cursor: default;
  user-select: none;
}
.beta-badge:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- 工具栏 ---------- */
#toolbar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
#toolbar::-webkit-scrollbar { display: none; }

.btn-group {
  display: flex;
  gap: 2px;
}

/* 图标按钮（28×28 圆形 hover） */
.icon-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: var(--r-btn);
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease;
}
.icon-btn:hover { background: var(--hover-strong); }
.icon-btn:active { background: var(--separator-strong); }

/* 语言切换钮（页头右上角，三页面共用视觉：macOS 圆角药丸） */
.lang-toggle {
  min-width: 34px;
  height: 26px;
  padding: 0 9px;
  border: 1px solid var(--separator-strong);
  border-radius: var(--r-btn);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.lang-toggle:hover { background: var(--hover-strong); }
.lang-toggle:active { background: var(--separator-strong); }

/* 分段控件（NSSegmentedControl） */
.seg-control {
  display: inline-flex;
  align-items: center;
  background: var(--seg-bg);
  border-radius: var(--r-row);
  padding: 2px;
  gap: 0;
}
.seg-control .seg {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1.4;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.seg-control .seg:hover:not(.active) { color: var(--text); }
.seg-control .seg.active {
  background: #fff;
  box-shadow: var(--shadow-sm);
  font-weight: 500;
}
/* ROI 选中态沿用 accent 语义：白底加微阴影（分段风格），保持与 NSSegmentedControl 一致 */
.roi-group .seg.active { color: var(--accent); }

/* 通用工具按钮（扁平） */
.tool-btn {
  border: none;
  background: transparent;
  color: var(--text);
  padding: 5px 11px;
  border-radius: var(--r-btn);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.12s ease;
  white-space: nowrap;
}
.tool-btn:hover:not(:disabled) { background: var(--hover-strong); }
.tool-btn:active:not(:disabled) { background: var(--separator-strong); }
.tool-btn:disabled { opacity: 0.35; cursor: default; }

/* 主操作按钮：accent 白字 */
.btn.primary, .tool-btn.primary {
  background: var(--accent);
  color: #fff;
  border: none;
}
.btn.primary:hover:not(:disabled), .tool-btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}
.btn.primary:disabled, .tool-btn.primary:disabled {
  background: var(--text-3);
  cursor: default;
}

/* 通用按钮基类（侧边栏等处） */
.btn {
  border-radius: var(--r-btn);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.12s ease;
  white-space: nowrap;
  border: none;
  padding: 6px 12px;
}
.btn.secondary {
  background: #fff;
  color: var(--text);
  border: 0.5px solid var(--separator-strong);
  box-shadow: var(--shadow-sm);
}
.btn.secondary:hover { background: var(--hover); }
.btn.danger {
  background: var(--danger-tint);
  color: var(--danger);
}
.btn.danger:hover:not(:disabled) { background: rgba(255, 59, 48, 0.2); }
.btn.block { display: block; width: 100%; }
.btn.small { padding: 4px 10px; font-size: 12px; }

/* ROI 激活态（兼容旧 .roi-btn.active 引用） */
.roi-btn.active { color: var(--accent); }
/* ROI 分段禁用态（本次分享不允许该尺寸） */
.seg-control .seg.disabled,
.roi-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* "显示全部标记" 激活态：accent 描边底 */
.tool-btn.active {
  background: var(--accent-fill);
  color: var(--accent);
}
.tool-btn.active:hover:not(:disabled) { background: var(--accent-fill); }

/* mpp 设置区 */
.mpp-setter {
  display: flex;
  align-items: center;
  gap: 4px;
}
#mpp-input {
  width: 78px;
  padding: 4px 8px;
  border: 0.5px solid var(--separator-strong);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  background: #fff;
}
#mpp-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-fill); }

.spacer { flex: 1; }

/* 缩放百分比徽章（白底灰边 pill，等宽数字；数字放大后缀不换行） */
.zoom-badge {
  background: #fff;
  color: var(--text);
  border: 0.5px solid var(--separator-strong);
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  min-width: 56px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
  flex-shrink: 0;
}

/* 工具栏分组分隔线（HIG：功能组之间留白 + 细分隔符，形成视觉层级） */
.tb-sep {
  width: 0.5px;
  height: 20px;
  background: var(--separator-strong);
  margin: 0 2px;
  flex-shrink: 0;
}

/* 键盘焦点环（HIG 键盘导航可见性） */
#toolbar .tool-btn:focus-visible,
#toolbar .icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ⋯ 溢出钮与面板：默认隐藏；桌面（min-width:769px 块）与移动端各自启用 */
.tbb-more-btn { display: none; }
.tbb-more { display: none; }
.tbb-more-mask { display: none; }

/* ---------- 桌面端 ⋯ 溢出菜单（低频操作：Reset / 显示全部标记） ---------- */
@media (min-width: 769px) {
  #app-header { position: relative; }
  #toolbar .tbb-more-btn {
    display: inline-flex;
    flex-shrink: 0;
  }
  /* macOS 菜单样式：半透明模糊底、圆角浮层、整行菜单项。
     绝对定位于 header 正下方右侧；#toolbar 非定位元素，不会裁剪 */
  #toolbar .tbb-more {
    position: absolute;
    top: calc(100% + 6px);
    right: 12px;
    flex-direction: column;
    align-items: stretch;
    gap: 1px;
    min-width: 168px;
    padding: 5px;
    background: var(--toolbar-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 0.5px solid var(--separator);
    border-radius: 10px;
    box-shadow: var(--shadow-float);
    z-index: 500;
  }
  #toolbar .tbb-more.open { display: flex; }
  #toolbar .tbb-more .tool-btn {
    display: flex;
    width: 100%;
    justify-content: flex-start;
    padding: 6px 10px;
    font-size: 13px;
    border-radius: 6px;
  }
  /* 桌面端工具栏已有 ✨AI 主钮，菜单里不再重复 */
  #toolbar .tbb-more #tbb-more-ai { display: none; }
  /* §3.3 宽度分组：搬入 ⋯ 菜单的真实节点（视图/标注组、画质、通道、mpp）。
     DOM 是原班节点（同一状态机），这里只调排版不复制交互。 */
  #toolbar .tbb-more .btn-group,
  #toolbar .tbb-more .view-tools,
  #toolbar .tbb-more .anno-tools {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 2px;
    padding: 2px 4px;
  }
  #toolbar .tbb-more .viewer-quality-host,
  #toolbar .tbb-more .mpp-setter {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
  }
  #toolbar .tbb-more .rgb-mode-badge { margin: 4px 10px; }
  .tbb-more-mask {
    position: fixed;
    inset: 0;
    z-index: 490;
  }
  .tbb-more-mask.open { display: block; }
}

/* =========================================================================
   工具栏锚定 popover + 宽度分组（升级 Review 2026-09-09 §3.3–3.5）
   ========================================================================= */
/* 浮层由 JS 以 fixed 坐标定位（打开时按触发按钮计算，打开期间重挂到
   body 以脱离 #toolbar 的裁剪/包含块）；同一时间至多一个浮层。 */
.toolbar-pop {
  position: fixed;
  z-index: 520;
  background: var(--toolbar-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 0.5px solid var(--separator);
  border-radius: 10px;
  box-shadow: var(--shadow-float);
  padding: 10px 12px;
}
.toolbar-pop[hidden] { display: none !important; }

/* 矩形尺寸 popover：沿用原设置区内部排版（宽/高/单位/锁比例/预设） */
.roi-settings.toolbar-pop { display: inline-flex; }

/* 矩形尺寸主行摘要（如 6×6 mm）：有选区才显示 */
.roi-summary {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--seg-bg, rgba(0, 0, 0, 0.05));
  border-radius: 6px;
  padding: 2px 7px;
  white-space: nowrap;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.roi-summary[hidden] { display: none !important; }

/* 标注选项 popover（标注名称（可选）迁入） */
.anno-pop { display: flex; flex-direction: column; gap: 4px; min-width: 200px; }
.anno-pop-field { display: flex; flex-direction: column; gap: 4px; }
.anno-pop-label { font-size: 11px; color: var(--text-2); }
.anno-pop .anno-label-input { width: 180px; }
.anno-more-btn { font-size: 10px; color: var(--text-3); }

/* 宽度分组档位标记：折叠档隐藏悬空分隔线（组已搬入 ⋯ 菜单） */
#toolbar.tb-tier-mid .tb-sep,
#toolbar.tb-tier-narrow .tb-sep { display: none; }

/* ---------- 账户 chip + popover（§3.5） ---------- */
.acct-wrap {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.acct-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 160px;
  height: 26px;
  padding: 0 8px;
  border: 0.5px solid var(--separator-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s ease;
}
.acct-btn:hover { background: var(--hover-strong); }
.acct-btn[hidden] { display: none; }
.acct-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.acct-btn-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.acct-btn-caret { font-size: 9px; color: var(--text-3); }

.acct-pop {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 240px;
  max-width: 300px;
  font-size: 12px;
}
.acct-pop-preview {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 600;
  color: #6b5a00;
  background: #fff6d6;
  border-radius: 6px;
  padding: 2px 8px;
}
.acct-pop-preview[hidden] { display: none; }
.acct-pop-email {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}
.acct-pop-role-row { display: flex; gap: 6px; color: var(--text-2); }
.acct-pop-role-label { color: var(--text-3); }
.acct-pop-balance {
  border-top: 0.5px solid var(--separator);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.acct-pop-balance-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--text-3);
  font-size: 11px;
}
.acct-pop-scope { color: var(--accent); font-weight: 600; }
.acct-pop-remaining {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.acct-pop-detail {
  color: var(--text-2);
  font-size: 11px;
  line-height: 1.5;
  word-break: break-word;
}
.acct-settings {
  align-self: stretch;
  text-align: left;
  border: none;
  border-top: 0.5px solid var(--separator);
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 8px 0 0;
  cursor: pointer;
}
.acct-settings:hover { text-decoration: underline; }
.acct-settings[hidden] { display: none; }

/* 顶部栏缩放徽章：桌面隐藏（桌面用底栏 #zoom-badge），仅移动端显示 */
.header-zoom-badge { display: none; }

/* 1:1 原始像素按钮（F3）：紧贴倍率徽章的紧凑 pill，不撑破工具栏 */
.zoom-native-btn {
  flex-shrink: 0;
  padding: 3px 8px;
  font-size: 11px;
  line-height: 1;
  font-family: var(--mono);
  color: var(--text);
  background: #fff;
  border: 0.5px solid var(--separator-strong);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.zoom-native-btn:hover { background: var(--hover); }
.zoom-native-btn:active { background: var(--hover-strong); }

/* =========================================================================
   主体布局
   ========================================================================= */
#main {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* 侧栏抽屉遮罩（手机端）：默认隐藏，抽屉打开时 .open 显示 */
.sidebar-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  z-index: 290;
}
.sidebar-mask.open { display: block; }

/* ---------- 左侧边栏：Finder 源列表风 ---------- */
#sidebar {
  width: 320px;
  background: var(--sidebar-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-right: 0.5px solid var(--separator);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  /* 升级 A：桌面收起/展开的宽度过渡（手机抽屉仍走 transform 过渡）。
     宽度变化由 OSD 容器 ResizeObserver + app.js 的 onLayoutChange 同步 Viewer */
  transition: width 0.18s ease;
}

/* 升级 A（§4.1/§4.2）：桌面收起态——切片列表不占布局宽度，Viewer 用足释放空间。
   收起内容 visibility:hidden：退出 tab 顺序与无障碍树，而非只移出视口。
   只在桌面断点生效；手机抽屉由 ≤768px 媒体查询的 transform 规则接管 */
@media (min-width: 769px) {
  #sidebar.collapsed {
    width: 0;
    min-width: 0;
    border-right-width: 0;
    visibility: hidden;
  }
}

/* 升级 A：切片搜索框（侧栏顶部，纯前端过滤；列表重渲后自动重放条件） */
.slide-search {
  width: 100%;
  padding: 6px 10px;
  border: 0.5px solid var(--separator-strong);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
}
.slide-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-fill); }
.slide-search::placeholder { color: var(--text-3); }

.sidebar-top {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 0.5px solid var(--separator);
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 16px;
}

/* 侧栏底部：退出登录链接（低调次要文字） */
.sidebar-bottom {
  padding: 8px 12px 12px;
  border-top: 0.5px solid var(--separator);
}

.logout-link {
  display: inline-block;
  font-size: 11px;
  color: var(--text-2);
  text-decoration: none;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  cursor: pointer;
}

.logout-link:hover {
  color: var(--text);
  text-decoration: underline;
}

/* 分区小标题 */
.section-head {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-2);
  letter-spacing: 0.5px;
  font-weight: 600;
  padding: 10px 8px 4px;
}
.section-head.row {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border-radius: var(--r-btn);
  text-transform: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0;
}
.section-head.row:hover { background: var(--hover); }
.section-head .caret {
  display: inline-block;
  transition: transform 0.15s ease;
  font-size: 10px;
  color: var(--text-3);
  width: 12px;
}
.section.collapsed .caret { transform: rotate(-90deg); }
.section.collapsed .section-body { display: none; }
.section-title { flex: 1; color: var(--text); }

.count-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  background: var(--hover-strong);
  padding: 0 7px;
  border-radius: var(--r-pill);
  line-height: 16px;
}

.section-body { padding: 2px 0 4px; }

/* 上传进度条 */
.progress-wrap {
  height: 20px;
  background: var(--hover-strong);
  border-radius: var(--r-pill);
  position: relative;
  overflow: hidden;
}
.progress-bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: var(--accent);
  border-radius: var(--r-pill);
  transition: width 0.2s ease;
}
.progress-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text);
  font-weight: 600;
  font-family: var(--mono);
  z-index: 1;
}

/* U3：多文件各自独立进度行（名称 + 独立进度条 + 三段状态） */
.upload-progress-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.upload-item {
  padding: 6px 8px;
  border: 1px solid var(--hover-strong);
  border-radius: var(--r-row);
  background: var(--hover);
}
.upload-item-name {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-item-bar {
  height: 6px;
  margin: 5px 0 4px;
  background: var(--hover-strong);
  border-radius: var(--r-pill);
  position: relative;
  overflow: hidden;
}
.upload-item-bar-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: var(--accent);
  border-radius: var(--r-pill);
  transition: width 0.2s ease;
}
.upload-item-bar-fill.upload-item-bar-error { background: var(--danger); }
.upload-item-status {
  font-size: 11px;
  color: var(--text);
}
.upload-item.upload-item-error .upload-item-status { color: var(--danger); }

/* =========================================================================
   项目行（Finder 风源列表行）
   ========================================================================= */
.project-list { padding: 0; }

.proj-empty {
  color: var(--text-3);
  font-size: 12px;
  text-align: center;
  padding: 16px 8px;
}

/* 项目行 */
.proj-row {
  border-radius: var(--r-row);
  margin-bottom: 1px;
  overflow: hidden;
}
.proj-row:hover { background: var(--hover); }
.proj-row.selected { background: var(--hover-strong); }

.proj-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  cursor: default;
  min-width: 0;
}
.proj-head .chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-2);
  font-size: 12px;
  transition: transform 0.15s ease;
  cursor: pointer;
  border-radius: 4px;
}
.proj-head .chevron:hover { background: var(--hover-strong); }
.proj-row.expanded .chevron { transform: rotate(90deg); }

.proj-head .icon { flex-shrink: 0; font-size: 14px; line-height: 1; }

.proj-head .ph-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.proj-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.proj-meta {
  font-size: 11px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.proj-meta .pm-note {
  color: var(--text-2);
}

.proj-head .proj-count {
  font-size: 11px;
  color: var(--text-2);
  background: var(--hover-strong);
  padding: 0 7px;
  border-radius: var(--r-pill);
  line-height: 16px;
  flex-shrink: 0;
  font-weight: 500;
}

/* 行内操作按钮（hover 浮现） */
.proj-ops {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.proj-row:hover .proj-ops,
.proj-row.selected .proj-ops { opacity: 1; }
.proj-op {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-2);
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, color 0.12s ease;
}
.proj-op:hover { background: var(--hover-strong); color: var(--text); }
.proj-op.po-del:hover { background: var(--danger-tint); color: var(--danger); }

/* 展开体：切片列表 */
.proj-body {
  padding: 1px 0 4px 20px;
  display: none;
  flex-direction: column;
  gap: 1px;
}
.proj-row.expanded .proj-body { display: flex; }

/* =========================================================================
   切片行（slide-row）
   ========================================================================= */
.slide-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: var(--r-row);
  margin-bottom: 1px;
  cursor: pointer;
  transition: background 0.12s ease;
  min-width: 0;
}
.slide-row:hover { background: var(--hover-strong); }
.slide-row.active {
  background: var(--accent);
}
.slide-row.active .slide-name,
.slide-row.active .slide-meta,
.slide-row.active .sr-icon,
.slide-row.active .slide-check,
.slide-row.active .slide-del { color: #fff; }
.slide-row.active .slide-meta { color: rgba(255, 255, 255, 0.8); }

.sr-icon {
  flex-shrink: 0;
  font-size: 13px;
  line-height: 1;
  color: var(--text-2);
}

.slide-check {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: var(--accent);
}

.slide-mid {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
/* 第一行：文件名（左）+ 标注 pill（右） */
.slide-top {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.slide-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* 第二行：meta 独占整行，不被右侧元素挤压 */
.slide-meta {
  font-size: 11px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 标注 pill（accent 12% 底、accent 字） */
.anno-pill {
  flex-shrink: 0;
  background: var(--accent-fill);
  color: var(--accent);
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: var(--r-pill);
  cursor: pointer;
  white-space: nowrap;
  border: none;
  line-height: 1.3;
}
.slide-row.active .anno-pill {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}
.anno-pill:hover { filter: brightness(0.96); }

/* 删除切片小 ×（hover 浮现） */
.slide-del {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.slide-row:hover .slide-del { opacity: 1; }
.slide-del:hover { background: var(--danger-tint); color: var(--danger); }

/* ---------- 新建项目表单（内联） ---------- */
.new-project-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.new-project-form input {
  padding: 5px 9px;
  border: 0.5px solid var(--separator-strong);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  background: #fff;
}
.new-project-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-fill); }
.np-actions { display: flex; gap: 6px; }
.np-actions .btn { flex: 1; }
.np-actions .np-cancel { flex: 0 0 auto; }

/* ---------- 未归类区 ---------- */
.unfiled-list {
  display: flex;
  flex-direction: column;
  padding-left: 12px;
}
.unfiled-empty { color: var(--text-3); font-size: 12px; text-align: center; padding: 10px 4px; }
.unfiled-ops {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  padding-left: 12px;
}
.unfiled-ops .btn { flex: 1; }

/* =========================================================================
   分享管理
   ========================================================================= */
.share-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

/* 链接权限显式选择（docs §8.3）：仅查看为基线（锁定），标注/下载默认不勾选 */
.share-perms {
  align-items: center;
  flex-wrap: wrap;
}
.perm-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text);
  padding: 3px 8px;
  border: 0.5px solid var(--separator-strong);
  border-radius: var(--r-pill);
  cursor: pointer;
  user-select: none;
}
.perm-chip input[type="checkbox"] {
  margin: 0;
  accent-color: var(--accent);
}
.perm-chip input:disabled { cursor: default; }
.share-perm-hint {
  font-size: 10.5px;
  color: var(--text-3);
  margin: 2px 0 6px;
}
.select {
  flex: 1;
  padding: 5px 8px;
  border: 0.5px solid var(--separator-strong);
  border-radius: var(--r-btn);
  font-size: 12px;
  font-family: inherit;
  background: #fff;
  outline: none;
  cursor: pointer;
}
.select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-fill); }
.input {
  width: 80px;
  padding: 5px 8px;
  border: 0.5px solid var(--separator-strong);
  border-radius: var(--r-btn);
  font-size: 12px;
  font-family: inherit;
  outline: none;
  background: #fff;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-fill); }

/* 创建结果 */
.share-result {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  padding: 8px;
  background: var(--accent-fill);
  border-radius: var(--r-btn);
}
.share-result-url {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  border: 0.5px solid var(--separator-strong);
  border-radius: 6px;
  font-size: 11px;
  font-family: var(--mono);
  background: #fff;
  color: var(--accent);
  outline: none;
  overflow: hidden;
}

/* 分享列表（行式） */
.share-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.share-empty { color: var(--text-3); font-size: 12px; text-align: center; padding: 12px 4px; }

/* 单条分享行 */
.share-row-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--r-row);
  transition: background 0.12s ease;
}
.share-row-item:hover { background: var(--hover-strong); }

.sr-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sr-status-dot.active { background: #34C759; }
.sr-status-dot.expired { background: var(--text-3); }
.sr-status-dot.revoked { background: var(--danger); }

.sr-mid {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.sr-token {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sr-meta {
  font-size: 11px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sr-meta .sr-sep { color: var(--text-3); margin: 0 2px; }

/* 行内操作（hover 浮现） */
.sr-ops {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.share-row-item:hover .sr-ops { opacity: 1; }
.sr-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-2);
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, color 0.12s ease;
}
.sr-btn:hover { background: var(--hover-strong); color: var(--text); }
.sr-btn.sr-revoke:hover { background: var(--danger-tint); color: var(--danger); }
.sr-btn:disabled { opacity: 0.3; cursor: default; }

/* =========================================================================
   右侧查看器
   ========================================================================= */
#viewer-wrap {
  flex: 1;
  position: relative;
  background: var(--viewer-bg);
  min-width: 0;
}
#viewer { width: 100%; height: 100%; }

/* 升级 A：无切片空态（正式版与 Demo 共用）。只盖住 viewer 背景，
   卡片外不拦截指针（拖拽上传等行为不受影响）；切片打开后由 JS 隐藏 */
.viewer-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}
.viewer-empty[hidden] { display: none; }
.viewer-empty-card {
  pointer-events: auto;
  text-align: center;
  padding: 28px 36px;
  border-radius: var(--r-panel);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  box-shadow: var(--shadow-float);
  max-width: min(86%, 420px);
}
.viewer-empty-title {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.viewer-empty-sub {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--text-2);
}

/* 底图缩略图层 */
.osd-base-thumb {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  object-fit: fill;
  filter: blur(1px);
  opacity: 0.9;
  pointer-events: none;
  z-index: 0;
  image-rendering: auto;
  transform-origin: center;
}

/* 拖拽上传遮罩 */
.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 122, 255, 0.15);
  border: 3px dashed var(--accent);
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}
.drop-overlay.active { display: flex; }
.drop-text {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20px);
  padding: 12px 24px;
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-float);
}

/* ---------- ROI 选区 overlay ---------- */
#roi-box {
  position: absolute;
  left: 0; top: 0;
  border: 2px solid #FFD700;
  background: transparent;
  cursor: move;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.9), 0 0 12px rgba(255, 215, 0, 0.5);
  z-index: 6;
}
#roi-box .roi-corner {
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #FFD700;
  border: 1.5px solid #fff;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.4);
}
#roi-box .roi-corner.tl { top: -5px; left: -5px; }
#roi-box .roi-corner.tr { top: -5px; right: -5px; }
#roi-box .roi-corner.bl { bottom: -5px; left: -5px; }
#roi-box .roi-corner.br { bottom: -5px; right: -5px; }
/* 升级 C（§6.1）：四角（双轴）+ 四边中点（单轴）手柄 */
#roi-box .roi-handle {
  position: absolute;
  width: 12px; height: 12px;
  background: #FFD700;
  border: 1.5px solid #fff;
  border-radius: 2px;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.4);
  z-index: 1;
}
#roi-box .roi-handle.roi-tl { top: -6px; left: -6px; cursor: nwse-resize; }
#roi-box .roi-handle.roi-tr { top: -6px; right: -6px; cursor: nesw-resize; }
#roi-box .roi-handle.roi-bl { bottom: -6px; left: -6px; cursor: nesw-resize; }
#roi-box .roi-handle.roi-br { bottom: -6px; right: -6px; cursor: nwse-resize; }
#roi-box .roi-handle.roi-t { top: -6px; left: 50%; margin-left: -6px; cursor: ns-resize; }
#roi-box .roi-handle.roi-b { bottom: -6px; left: 50%; margin-left: -6px; cursor: ns-resize; }
#roi-box .roi-handle.roi-l { left: -6px; top: 50%; margin-top: -6px; cursor: ew-resize; }
#roi-box .roi-handle.roi-r { right: -6px; top: 50%; margin-top: -6px; cursor: ew-resize; }
/* 矩形工具入口 + 紧凑设置区（宽/高/单位/锁比例/预设） */
.roi-rect-wrap { display: inline-flex; align-items: center; gap: 4px; }
.roi-rect-btn.active { color: var(--accent); }
.roi-settings {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 9px;
  background: var(--seg-bg, rgba(0,0,0,0.05));
  font-size: 12px;
}
.roi-settings[hidden] { display: none; }
.roi-set-field { display: inline-flex; align-items: center; gap: 3px; color: var(--text-2, inherit); }
.roi-settings .roi-num {
  width: 68px;
  height: 26px;
  padding: 0 5px;
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 6px;
  font-size: 12px;
  background: transparent;
  color: inherit;
}
.roi-settings .roi-unit,
.roi-settings .roi-preset {
  height: 26px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-size: 12px;
}
.roi-set-lock {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  color: var(--text-2, inherit);
  white-space: nowrap;
}
#roi-box .roi-label {
  position: absolute;
  top: -24px;
  left: 0;
  background: #FFD700;
  color: #5a3500;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* =========================================================================
   toast（macOS 通知风：顶部居中）
   ========================================================================= */
#toast-container {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 10px 16px;
  border-radius: 10px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  background: rgba(40, 40, 42, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-float);
  animation: toast-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
  max-width: 380px;
  word-break: break-word;
  pointer-events: auto;
}
.toast.success { background: rgba(48, 138, 76, 0.95); }
.toast.error   { background: rgba(196, 64, 54, 0.95); }
.toast.info    { background: rgba(40, 40, 42, 0.92); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* iOS 风 slide-up + fade（移动端底部抽屉/面板用） */
@keyframes sheet-up {
  from { transform: translateY(40%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* =========================================================================
   切片选择器浮层（macOS sheet 风）
   ========================================================================= */
.picker-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
}
.picker-dialog {
  width: min(440px, 92%);
  max-height: 80%;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-float);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.picker-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 0.5px solid var(--separator);
  font-size: 13px;
  font-weight: 600;
}
.icon-btn.close {
  width: 24px;
  height: 24px;
  font-size: 18px;
}
/* 菜单按钮（升级 A）：全断点可见的侧栏开合入口——桌面=收起/展开侧栏，
   手机=侧滑抽屉；状态文案（展开/收起侧栏）由 app.js 按断点同步 */
.icon-btn.menu-btn {
  display: inline-flex;
  width: 32px;
  height: 32px;
  font-size: 18px;
  flex-shrink: 0;
}

/* 桌面端：上下文分组透明（display:contents），按钮照常内联；
   仅移动端媒体查询把它变成底栏上下文条。 */
.tbb-context { display: contents; }
/* 桌面端隐藏移动端 ROI 滑块分段（桌面用 #roi-6/#roi-6-5 分段） */
.roi-slider { display: none; }
.picker-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
}
.picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--r-btn);
  cursor: pointer;
  transition: background 0.12s ease;
}
.picker-item:hover { background: var(--hover); }
.picker-item input { accent-color: var(--accent); flex-shrink: 0; }
.picker-item .pi-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}
.pi-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pi-meta { font-size: 10px; color: var(--text-2); }
.picker-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 0.5px solid var(--separator);
}
.picker-count { font-size: 12px; color: var(--text-2); }

/* =========================================================================
   通道着色说明卡（Batch 4；channel-controls.js 渲染，正式版与 Demo 共用）
   面板宿主 #channel-panel 位于 #viewer-wrap 内（与 .anno-panel 同一锚定）；
   控件不只靠颜色传达状态：勾选态 + 文本 + 焦点样式 + aria-label。
   ========================================================================= */
.rgb-mode-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-3);
  background: var(--seg-bg);
  border-radius: 999px;
  white-space: nowrap;
}
.rgb-mode-badge[hidden] { display: none; }

.channel-panel {
  position: absolute;
  right: 14px;
  top: 14px;
  width: 300px;
  max-width: calc(100% - 28px);
  max-height: calc(100% - 28px);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-float);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 56;
  font-size: 12px;
}
.channel-panel[hidden] { display: none; }
.ch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 0.5px solid var(--separator);
  font-size: 13px;
  font-weight: 600;
}
.ch-title { color: var(--text); }
.ch-close {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  font-size: 16px;
  line-height: 1;
  color: var(--text-3);
  cursor: pointer;
  border-radius: var(--r-btn);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ch-close:hover { background: var(--hover); color: var(--text); }
/* 键盘可达（§4.2）：焦点态不只靠颜色，还有描边 */
.ch-close:focus-visible,
.channel-panel input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.ch-subtitle {
  margin: 0;
  padding: 8px 12px 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-2);
}
.ch-plane-warn {
  margin: 8px 12px 0;
  padding: 6px 8px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text);
  background: var(--seg-bg);
  border-radius: var(--r-btn);
}
.ch-count { padding: 8px 12px 0; font-size: 12px; font-weight: 600; color: var(--text); }
.ch-meta { padding: 2px 12px 0; font-size: 11px; color: var(--text-2); }
.ch-ai-badge {
  margin: 8px 12px 0;
  padding: 6px 8px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-2);
  background: var(--accent-fill);
  border-radius: var(--r-btn);
}
.ch-ai-badge[hidden] { display: none; }
.ch-list { overflow-y: auto; padding: 6px 6px 10px; }
.ch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--r-btn);
}
.ch-row:hover { background: var(--hover); }
.ch-row input[type="checkbox"] {
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}
.ch-label {
  /* 名称列永不被警示/来源挤出可视区（2026-09-05 UI 修复）：basis 0 会让
     带 .ch-invisible-reason 的行把 label 压到 0 宽（名称+Cn 全消失）。
     下限 96px 保住名称（超长走省略号），溢出改由 origin/reason 收缩承担。 */
  flex: 1 1 auto;
  min-width: 96px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  cursor: pointer;
}
.ch-name {
  color: var(--text);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ch-index { color: var(--text-3); font-family: var(--mono); font-size: 10px; }
.ch-color {
  flex-shrink: 0;
  width: 26px;
  height: 20px;
  padding: 0;
  border: 1px solid var(--separator-strong);
  border-radius: 5px;
  background: none;
  cursor: pointer;
}
.ch-origin {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
  color: var(--text-2);
}
.ch-row-disabled .ch-name,
.ch-row-disabled .ch-origin { color: var(--text-3); }

/* 有效不可见（F4）：勾选但对合成贡献为 0 的行——短文本标注原因，
   不自动改色；虚线描边只提示色块本身尚未参与合成 */
.ch-invisible .ch-color { outline: 1px dashed var(--separator-strong); }
.ch-invisible-reason {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 46%;
  font-size: 10px;
  line-height: 1.3;
  color: var(--danger);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 移动端（325px 宽）：说明卡贴满查看器宽度 */
@media (max-width: 480px) {
  .channel-panel { right: 8px; left: 8px; top: 8px; width: auto; max-width: none; }
}

/* =========================================================================
   标注面板（macOS 浮动面板风）
   ========================================================================= */
.anno-panel {
  position: absolute;
  right: 14px;
  top: 14px;
  bottom: 14px;
  width: 300px;
  max-width: 90%;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-float);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 55;
}
.anno-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 0.5px solid var(--separator);
  font-size: 13px;
  font-weight: 600;
}
/* 面板头部右侧操作容器（眼睛切换 + 关闭） */
.anno-panel-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
/* 「显示/隐藏全部标记」眼睛钮（面板头部）：active = 显示全部 */
.panel-eye-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  font-size: 15px;
  line-height: 1;
  color: var(--text-3);
  cursor: pointer;
  border-radius: var(--r-btn);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, color 0.12s ease;
  opacity: 0.7;
}
.panel-eye-btn:hover { background: var(--hover); color: var(--text); opacity: 1; }
.panel-eye-btn.active {
  color: var(--accent);
  background: var(--accent-fill);
  opacity: 1;
}
.anno-panel-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.anno-panel-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}
.anno-panel-empty { color: var(--text-3); font-size: 13px; text-align: center; padding: 20px 8px; }
.anno-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  margin-bottom: 2px;
}
.anno-group-head .agh-label { font-size: 11px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.3px; }
.anno-group-head .agh-count { font-size: 11px; color: var(--text-3); }
.anno-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--r-row);
  cursor: pointer;
  transition: background 0.12s ease;
}
.anno-item:hover { background: var(--hover); }
.anno-item .ai-info { flex: 1 1 150px; min-width: 0; }
.anno-item .ai-title { font-size: 12px; font-weight: 500; color: var(--text); }
.anno-item .ai-title .ai-label { color: var(--accent); font-weight: 600; }
.anno-item .ai-title .ai-type-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  margin-right: 4px;
  border-radius: 4px;
  background: var(--accent-fill);
  color: var(--accent);
  font-size: 10px;
}
.anno-item .ai-sub { font-size: 10px; color: var(--text-2); margin-top: 2px; word-break: break-all; }

/* 未公开标注（P1-7）：不再整行降透明度（会让操作按钮看起来像 disabled）。
   只把名称文字调暗，并配「私有」小徽章表达私有状态；操作按钮保持正常不透明度。 */
.anno-item.anno-private .ai-title .ai-label { color: var(--text-3); }
.anno-private-badge {
  display: inline-flex;
  align-items: center;
  font-size: 9px;
  font-weight: 600;
  line-height: 1;
  padding: 2px 5px;
  margin-left: 5px;
  border-radius: 4px;
  color: #9a6a00;
  background: rgba(255, 170, 0, 0.16);
  vertical-align: middle;
  white-space: nowrap;
}
/* 「公开」切换钮：未公开灰色，公开(accent)高亮 */
.anno-item .ai-share {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  border: none;
  border-radius: var(--r-row);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  opacity: 0.7;
  transition: background 0.12s ease, opacity 0.12s ease, color 0.12s ease;
}
.anno-item .ai-share:hover:not(:disabled) { background: var(--hover); opacity: 1; }
.anno-item .ai-share.on {
  color: var(--accent);
  background: var(--accent-fill);
  opacity: 1;
}
.anno-item .ai-share:disabled { cursor: default; opacity: 0.4; }

/* 「保存标记」按钮：与「保存图片」(primary) 区分，用 secondary 风格 */
.tool-btn.anno-save {
  background: #fff;
  color: var(--text);
  border: 0.5px solid var(--separator-strong);
  box-shadow: var(--shadow-sm);
}
.tool-btn.anno-save:hover:not(:disabled) { background: var(--hover); }
.tool-btn.anno-save:active:not(:disabled) { background: var(--separator-strong); }

/* 全部标记叠加框 */
.anno-overlay-box {
  position: absolute;
  left: 0; top: 0;
  border-radius: 2px;
  pointer-events: none;
  z-index: 5;
}
.anno-overlay-tag {
  position: absolute;
  top: -16px;
  left: -1px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  padding: 1px 5px;
  border-radius: 3px 3px 3px 0;
  white-space: nowrap;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 标注面板：编辑/删除钮（与 .ai-share 同尺寸风格） */
.anno-item .ai-op {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  border: none;
  border-radius: var(--r-row);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  opacity: 0.7;
  transition: background 0.12s ease, opacity 0.12s ease, color 0.12s ease;
}
.anno-item .ai-op:hover { background: var(--hover); opacity: 1; }
.anno-item .ai-edit:hover { color: var(--accent); background: var(--accent-fill); }
.anno-item .ai-del:hover { color: var(--danger); background: var(--danger-tint); }

/* 编辑卡（标注面板顶部） */
.anno-edit-wrap {
  padding: 6px 6px 2px;
  flex-shrink: 0;
}
.anno-edit-card {
  background: #fff;
  border: 0.5px solid var(--separator-strong);
  border-radius: var(--r-panel);
  padding: 8px;
  box-shadow: var(--shadow-sm);
}
.aec-head {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.aec-note {
  width: 100%;
  min-height: 40px;
  padding: 5px 7px;
  border: 0.5px solid var(--separator-strong);
  border-radius: var(--r-row);
  font-size: 12px;
  font-family: inherit;
  outline: none;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}
.aec-note:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-fill); }
.aec-ops {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  justify-content: flex-end;
}

/* =========================================================================
   滚动条（8px 细滚动条、半透明灰）
   ========================================================================= */
.sidebar-scroll::-webkit-scrollbar,
.share-list::-webkit-scrollbar,
.unfiled-list::-webkit-scrollbar,
.anno-panel-list::-webkit-scrollbar,
.picker-list::-webkit-scrollbar,
.ai-trace::-webkit-scrollbar,
#sidebar::-webkit-scrollbar { width: 8px; height: 8px; }
.sidebar-scroll::-webkit-scrollbar-thumb,
.share-list::-webkit-scrollbar-thumb,
.unfiled-list::-webkit-scrollbar-thumb,
.anno-panel-list::-webkit-scrollbar-thumb,
.picker-list::-webkit-scrollbar-thumb,
.ai-trace::-webkit-scrollbar-thumb,
#sidebar::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.sidebar-scroll::-webkit-scrollbar-thumb:hover,
.share-list::-webkit-scrollbar-thumb:hover,
.unfiled-list::-webkit-scrollbar-thumb:hover,
.anno-panel-list::-webkit-scrollbar-thumb:hover,
.picker-list::-webkit-scrollbar-thumb:hover,
.ai-trace::-webkit-scrollbar-thumb:hover,
#sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.35);
  background-clip: padding-box;
}
.sidebar-scroll::-webkit-scrollbar-track,
.share-list::-webkit-scrollbar-track,
.unfiled-list::-webkit-scrollbar-track,
.anno-panel-list::-webkit-scrollbar-track,
.picker-list::-webkit-scrollbar-track,
.ai-trace::-webkit-scrollbar-track,
#sidebar::-webkit-scrollbar-track { background: transparent; }

/* =========================================================================
   标注画布层 + 绘制工具 + 别名备注编辑
   ========================================================================= */
/* 标注画布层：瓦片之上、ROI 框之下；pointer-events 由绘制模式控制 */
.anno-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}
.anno-canvas.drawing {
  pointer-events: auto;
  cursor: crosshair;
}

/* 标注绘制工具按钮激活态（沿用 .tool-btn.active 风格） */
.anno-tools .tool-btn.active {
  background: var(--accent-fill);
  color: var(--accent);
}
/* 管理端"标注人"输入框 */
.anno-label-input {
  width: 110px;
  padding: 4px 8px;
  border: 0.5px solid var(--separator-strong);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  background: #fff;
}
.anno-label-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-fill); }

/* 切片行：别名显示 + 编辑态 */
.slide-name.alias-first { color: var(--text); }
.slide-name .alias-filename {
  color: var(--text-3);
  font-weight: 400;
  font-size: 11px;
  margin-left: 4px;
}
.slide-meta .sm-note { color: var(--text-2); }

/* 行内别名/备注编辑钮（hover 浮现，与删除钮并排） */
.slide-edit {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.slide-row:hover .slide-edit { opacity: 1; }
.slide-edit:hover { background: var(--accent-fill); color: var(--accent); }
.slide-row.active .slide-edit { color: #fff; }
.slide-row.active .slide-edit:hover { background: rgba(255, 255, 255, 0.2); }

/* 单独分享按钮（hover 浮现，与删除/编辑同风格） */
.slide-share {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.slide-row:hover .slide-share { opacity: 1; }
.slide-share:hover { background: var(--accent-fill); color: var(--accent); }
.slide-row.active .slide-share { color: #fff; }
.slide-row.active .slide-share:hover { background: rgba(255, 255, 255, 0.2); }

/* Demo 目录按钮（owner；加入/移出 Demo allowlist，PT-4 docs §5.1） */
.slide-demo {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.slide-row:hover .slide-demo { opacity: 1; }
.slide-demo:hover { background: var(--accent-fill); color: var(--accent); }
.slide-demo[aria-pressed="true"] { color: var(--accent); }
.slide-row.active .slide-demo { color: #fff; }
.slide-row.active .slide-demo:hover { background: rgba(255, 255, 255, 0.2); }

/* 行内编辑态：展开后替换原行内容 */
.slide-edit-form {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 0;
}
.slide-edit-form input {
  width: 100%;
  padding: 3px 7px;
  border: 0.5px solid var(--separator-strong);
  border-radius: 5px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  background: #fff;
}
.slide-edit-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-fill); }
.slide-edit-form .sef-actions { display: flex; gap: 6px; }
.slide-edit-form .sef-actions .btn { flex: 0 0 auto; }

/* 切片选择器 / chips 显示别名（picker-item 已有 pi-name，此处仅复用） */
.pi-name .pi-alias { color: var(--accent); font-weight: 600; }

/* =========================================================================
   响应式
   ========================================================================= */
@media (max-width: 768px) {
  /* 底栏高度变量：viewer / 上下文条 / 动作面板据此让位 */
  :root {
    --tbb-bar-h: 52px;
    --tbb-ctx-h: 52px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
  }

  /* 菜单按钮：手机端可见 */
  .icon-btn.menu-btn { display: inline-flex; }

  /* 侧栏改为抽屉：默认滑出屏外，.open 时滑入；桌面端布局完全不受影响 */
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(85vw, 340px);
    max-width: 340px;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    z-index: 300;
  }
  #sidebar.open { transform: none; }

  /* ---------- 顶部栏瘦身：只留 ☰ + 当前切片名 + zoom-badge ---------- */
  #app-header {
    flex-wrap: nowrap;
    height: auto;
    min-height: 52px;
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    row-gap: 4px;
    column-gap: 10px;
    align-items: center;
    /* 关键：移除 backdrop-filter——它会为内部 fixed 的 #toolbar 创建包含块，
       导致底栏被锚定在 header 内而非视口底部。去掉后 #toolbar 才能相对视口定位。 */
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    /* 去掉模糊后改用不透明底，避免半透明透出 viewer */
    background: var(--bg);
  }
  .title-group {
    flex: 1;
    min-width: 0;
    order: 0;
  }
  /* 手机端隐藏长标题文字，仅保留当前切片名 */
  .header-title,
  .title-sep { display: none; }

  /* ---------- 工具栏：脱离 header，固定到屏幕底部 ---------- */
  #toolbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    order: 0;
    flex-basis: auto;
    width: auto;
    height: calc(var(--tbb-bar-h) + var(--safe-bottom));
    padding: 6px 10px;
    padding-bottom: calc(6px + var(--safe-bottom));
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    overflow: visible;
    background: var(--toolbar-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-top: 0.5px solid var(--separator);
    z-index: 400;
  }
  /* 工具栏主按钮收紧：等宽分布，触控高度 ≥40px，无横向滚动 */
  #toolbar .icon-btn {
    width: 40px;
    height: 40px;
    font-size: 18px;
    flex-shrink: 0;
  }
  #toolbar .tool-btn {
    height: 36px;
    padding: 0 10px;
    font-size: 12px;
    min-height: 36px;
    flex-shrink: 0;
  }
  #toolbar .anno-tools { gap: 2px; }
  #toolbar .anno-tools .tool-btn { padding: 0 8px; font-size: 13px; }
  #toolbar .seg-control .seg { padding: 6px 8px; font-size: 11px; }
  /* 底栏空间紧张：折叠冗长文字（ROI 前缀、箭头/描图文字），只留紧凑图标/数字 */
  #toolbar .tb-txt { display: none; }
  /* spacer 推 zoom-badge + ⋯ 到右侧 */
  #toolbar .spacer { flex: 1 1 auto; }
  #toolbar .zoom-badge {
    flex-shrink: 0;
    order: 98;
    padding: 3px 8px;
    min-width: 46px;
    font-size: 11px;
  }

  /* —— 移动端：AI 读片钮收进 ⋯ 溢出面板；缩放徽章移到顶部栏右侧 —— */
  #toolbar #ai-btn { display: none; }          /* AI 主钮移动端藏起，进 ⋯ */
  #toolbar .zoom-badge { display: none; }       /* 底栏徽章藏起，改用顶部徽章 */
  .header-zoom-badge {
    display: inline-block;                      /* 移动端显示顶部徽章 */
    flex-shrink: 0;
    margin-left: auto;                          /* 顶到 header 右侧 */
    padding: 3px 10px;
    min-width: 52px;
    font-size: 12px;
  }
  #toolbar .tbb-more-btn {
    display: inline-flex;
    flex-shrink: 0;
    order: 99;                                   /* 排最右 */
  }
  /* §3.5：账户 chip 在窄屏底栏保持在最右（⋯ 之后），浮层向上弹出 */
  #toolbar .acct-wrap { order: 100; }
  #toolbar .acct-btn { height: 32px; max-width: 120px; }
  /* ⋯ 溢出面板：底栏上方弹出的紧凑行 */
  #toolbar .tbb-more {
    display: none;
    position: fixed;
    right: 10px;
    bottom: calc(var(--tbb-bar-h) + var(--safe-bottom) + 8px);
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--toolbar-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 0.5px solid var(--separator);
    border-radius: 12px;
    box-shadow: var(--shadow-float);
    z-index: 500;
  }
  #toolbar .tbb-more.open { display: flex; }
  #toolbar .tbb-more .tool-btn { height: 36px; padding: 0 12px; font-size: 13px; }
  /* ⋯ 遮罩：点外关闭 */
  .tbb-more-mask {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 490;
  }
  .tbb-more-mask.open { display: block; }

  /* —— 需求2：移动端隐藏 ± 缩放钮（双指缩放为主）；隐藏 ROI 分段，改用方框钮 —— */
  #toolbar #zoom-out,
  #toolbar #zoom-in { display: none; }
  #toolbar .roi-group { display: none; }
  #toolbar #anno-all-btn { display: none; }
  /* 桌面分组分隔线在底栏不占位 */
  #toolbar .tb-sep { display: none; }
  /* 底栏不再用 spacer 撑开：元素紧凑靠左，避免中间大片留白 */
  #toolbar .spacer { display: none; }

  /* —— ROI 滑块分段（取代旧 ▭ + 弹窗）：滑动拇指 + 点选，再点退出 —— */
  #toolbar .roi-slider {
    display: inline-flex;
    position: relative;
    align-items: center;
    height: 30px;
    padding: 2px;
    border-radius: 9px;
    background: var(--seg-bg);
    flex-shrink: 0;
    gap: 0;
  }
  #toolbar .roi-slider-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    height: calc(100% - 4px);
    width: 50%;
    border-radius: 7px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
    transition: transform 0.22s cubic-bezier(0.34, 1.4, 0.5, 1), opacity 0.18s ease;
    opacity: 0;
    z-index: 0;
    pointer-events: none;
  }
  #toolbar .roi-slider-seg {
    position: relative;
    z-index: 1;
    border: none;
    background: transparent;
    color: var(--text-2);
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    padding: 0 11px;
    height: 26px;
    min-width: 30px;
    border-radius: 7px;
    cursor: pointer;
    transition: color 0.18s ease, transform 0.12s ease;
    -webkit-tap-highlight-color: transparent;
  }
  #toolbar .roi-slider-seg:active { transform: scale(0.9); }
  #toolbar .roi-slider-seg.active { color: var(--accent); }
  #toolbar .roi-slider-seg.disabled { opacity: 0.35; pointer-events: none; }

  /* —— 旋转/镜像/复位 常驻底栏：紧凑图标/文字钮 —— */
  #toolbar .view-tools { display: inline-flex; gap: 2px; align-items: center; }
  #toolbar .view-tools .icon-btn { width: 32px; height: 32px; font-size: 16px; }
  #toolbar #reset-btn { padding: 0 8px; font-size: 11px; height: 32px; min-height: 32px; }

  /* ---------- mpp 手动设置（⋯ 移除后归入上下文条；JS 控制显隐，缺省隐藏） ---------- */
  #tbb-context .mpp-setter {
    flex: 1 1 100%;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 2px 0 0;
    height: auto;
    min-height: 36px;
  }
  #tbb-context .mpp-setter .tool-btn { width: auto; height: 32px; padding: 0 12px; font-size: 12px; flex-shrink: 0; }
  #tbb-context #mpp-input { width: 96px; height: 32px; }

  /* ---------- 上下文动作条（ROI/绘制激活时出现） ---------- */
  #tbb-context {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--tbb-bar-h) + var(--safe-bottom));
    z-index: 399;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    padding-bottom: 8px;
    background: var(--toolbar-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-top: 0.5px solid var(--separator);
    flex-wrap: wrap; /* mpp 设置出现时独占换行 */
    overflow: hidden;
  }
  body.ctx-on #tbb-context {
    display: flex;
    animation: toast-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1);
  }
  #tbb-context .anno-label-input {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    height: 36px;
    font-size: 13px;
  }
  #tbb-context .tool-btn {
    height: 36px;
    min-height: 36px;
    padding: 0 12px;
    font-size: 12px;
    flex-shrink: 0;
  }

  /* ---------- 查看器占满剩余宽度与高度（侧栏已脱离文档流），让位底栏 ---------- */
  #main { flex: 1; }
  #viewer-wrap,
  #viewer { width: 100%; height: 100%; }
  #viewer-wrap { padding-bottom: calc(var(--tbb-bar-h) + var(--safe-bottom)); }
  body.ctx-on #viewer-wrap {
    padding-bottom: calc(var(--tbb-bar-h) + var(--tbb-ctx-h) + var(--safe-bottom));
  }

  /* 标注面板：手机端贴底显示，上移到底栏之上，避免遮挡；需求1 加 slide-up + fade */
  .anno-panel {
    right: 8px; left: 8px; top: auto;
    bottom: calc(var(--tbb-bar-h) + 8px + var(--safe-bottom));
    width: auto; max-height: 55%;
    animation: sheet-up 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
  }
  body.ctx-on .anno-panel {
    bottom: calc(var(--tbb-bar-h) + var(--tbb-ctx-h) + 8px + var(--safe-bottom));
  }

  /* toast 上移，避开底栏 */
  #toast-container { top: calc(64px + env(safe-area-inset-top, 0px)); }
}

/* 更窄屏（≤480px）：主栏按钮进一步收紧，防溢出 */
@media (max-width: 480px) {
  #toolbar .icon-btn { width: 36px; height: 36px; font-size: 16px; }
  #toolbar .tool-btn { padding: 0 8px; font-size: 11px; }
  #toolbar .seg-control .seg { padding: 5px 7px; font-size: 10px; }
  #toolbar .anno-tools .tool-btn { padding: 0 6px; font-size: 12px; }
}

/* 极窄屏（≤380px） */
@media (max-width: 380px) {
  #toolbar .icon-btn { width: 34px; height: 34px; font-size: 15px; }
  #toolbar .tool-btn { padding: 0 6px; font-size: 10px; }
  #toolbar .seg-control .seg { padding: 4px 6px; font-size: 9px; }
  /* 极窄屏隐藏缩放百分比，保证 ⋯ 溢出钮始终可见可达 */
  #toolbar .zoom-badge { display: none; }
}

/* =========================================================================
   AI 读片助手面板（管理员）—— 仿 anno-panel 的浮动面板风
   ========================================================================= */
.ai-btn { color: var(--accent); }
.ai-btn:disabled { color: var(--text-3); opacity: 0.5; }

.ai-panel {
  position: absolute;
  right: 14px;
  top: 14px;
  bottom: 14px;
  width: 340px;
  max-width: 90%;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-float);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 56;
}
.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 0.5px solid var(--separator);
  font-size: 13px;
  font-weight: 600;
}
.ai-panel-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

/* AI 服务降级横幅（sidecar 不可达；平台功能不受影响） */
.ai-degrade-banner {
  margin: 8px 12px 0;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.4;
  color: #8a5a00;
  background: rgba(255, 204, 0, 0.16);
  border: 0.5px solid rgba(180, 130, 0, 0.35);
  border-radius: var(--r-row);
}

/* 1. 设置区 */
.ai-config-wrap {
  padding: 10px 12px;
  border-bottom: 0.5px solid var(--separator);
}
.ai-config-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 8px;
}
.ai-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-2);
}
.ai-field input {
  padding: 6px 8px;
  border: 0.5px solid var(--separator);
  border-radius: var(--r-btn);
  font-size: 13px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
}
.ai-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-fill);
}
/* 兼容/当前不生效字段：输入框置灰，附小字说明（不删除控件，保留兼容） */
.ai-field input.ai-field-legacy {
  background: rgba(127, 127, 127, 0.08);
  opacity: 0.7;
}
.ai-field-note {
  font-size: 10.5px;
  color: var(--text-3);
  opacity: 0.85;
}
.ai-field select {
  padding: 6px 8px;
  border: 0.5px solid var(--separator);
  border-radius: var(--r-btn);
  font-size: 13px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
}
.ai-field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-fill);
}
/* B1：AI 来源两卡（平台 AI / 自定义 API），user 专属，复用 seg-control 的视觉语言 */
.ai-source-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 10px;
}
.ai-source-card {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 8px 10px;
  border: 0.5px solid var(--separator);
  border-radius: var(--r-row);
  background: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.ai-source-card:hover { background: var(--hover); }
.ai-source-card input[type="radio"] {
  margin: 2px 0 0;
  accent-color: var(--accent);
  flex-shrink: 0;
}
.ai-source-card-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.ai-source-card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}
.ai-source-card-sub,
.ai-source-card-meta {
  font-size: 10.5px;
  color: var(--text-3);
  line-height: 1.4;
}
/* 选中态：accent 描边 + 浅底（对齐 seg.active / tool-btn.active 的 accent 语义） */
.ai-source-card.selected {
  border-color: var(--accent);
  background: var(--accent-fill);
}
/* 平台未配置：整卡置灰不可选（config-panel.js 同步 disabled + .disabled） */
.ai-source-card.disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: rgba(127, 127, 127, 0.06);
}
.ai-source-card.disabled:hover { background: rgba(127, 127, 127, 0.06); }
@media (max-width: 480px) {
  .ai-source-cards { grid-template-columns: 1fr; }
}
/* 高级调优折叠区（§8.1，默认收起） */
.ai-advanced {
  margin: 4px 0 8px;
  font-size: 12px;
  color: var(--text-3);
}
.ai-advanced > summary {
  cursor: pointer;
  padding: 2px 0;
  list-style: none;
}
.ai-advanced > summary::-webkit-details-marker { display: none; }
.ai-advanced > summary::before { content: "▸ "; }
.ai-advanced[open] > summary::before { content: "▾ "; }
.ai-config-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.ai-config-hint { font-size: 11px; color: var(--text-3); }

.ai-config-collapsed {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 0.5px solid var(--separator);
  font-size: 12px;
}
.ai-config-summary {
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
  text-decoration: underline;
  white-space: nowrap;
}
.link-btn:hover { opacity: 0.8; }

/* 会话切换器：紧凑单行下拉，列出本切片 main+branch（fork 不进列表） */
.ai-session-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-bottom: 0.5px solid var(--separator);
  background: rgba(255, 255, 255, 0.6);
  font-size: 11px;
  color: var(--text-3);
}
.ai-session-bar-label {
  flex: 0 0 auto;
  font-weight: 600;
  white-space: nowrap;
}
.ai-session-select {
  flex: 1 1 auto;
  min-width: 0;
  padding: 3px 6px;
  border: 0.5px solid var(--separator);
  border-radius: var(--r-btn);
  font-size: 11px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-session-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-fill);
}

/* 会话操作行（路径/查看视野/AI 描绘开关）：与小号按钮对齐 */
.hp-session-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* 「允许 AI 描绘」：iOS 风格开关（input 隐去，轨道+滑钮纯 CSS） */
.hp-drawing-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.hp-drawing-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.hp-drawing-toggle .hp-switch {
  position: relative;
  width: 32px;
  height: 19px;
  border-radius: 10px;
  background: var(--separator-strong);
  transition: background 0.18s ease;
  flex-shrink: 0;
}
.hp-drawing-toggle .hp-switch::after {
  content: "";
  position: absolute;
  top: 1.5px;
  left: 1.5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease;
}
.hp-drawing-toggle input:checked + .hp-switch { background: var(--accent); }
.hp-drawing-toggle input:checked + .hp-switch::after { transform: translateX(13px); }
.hp-drawing-toggle input:focus-visible + .hp-switch {
  box-shadow: 0 0 0 3px var(--accent-fill);
}
.hp-drawing-toggle input:disabled + .hp-switch { opacity: 0.4; }
.hp-drawing-toggle.hp-disabled { cursor: default; color: var(--text-3); }
.hp-drawing-toggle .hp-switch-label { font-size: 11px; }

/* 2. 底部输入（iMessage 输入栏：+ 圆钮 / pill 输入 / 蓝色发送圆钮） */
.ai-composer {
  padding: 8px 10px 10px;
  border-top: 0.5px solid var(--separator);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  flex-shrink: 0;
}
/* 辅助行（继续/新会话）：低调小字，仅在需要时出现 */
.ai-composer-aux {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 2px 6px;
}
.ai-composer-aux:empty { display: none; padding: 0; }
.ai-composer-aux .btn {
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--accent);
  font-size: 12px;
  padding: 2px 6px;
}
.ai-composer-aux .btn:hover { background: var(--accent-fill); }
.ai-composer-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
/* 左侧 + 圆钮（iMessage 的加号位，这里承载「判读当前选区」） */
.ai-plus-btn {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  margin-bottom: 2px;
  border: none;
  border-radius: 50%;
  background: var(--seg-bg);
  color: var(--text-2);
  font-size: 16px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, color 0.12s ease;
}
.ai-plus-btn:hover { background: var(--separator-strong); color: var(--text); }
.ai-plus-btn:active { background: var(--accent-fill); color: var(--accent); }
/* 输入 pill：白底细灰描边，iMessage 输入框形制 */
.ai-task {
  flex: 1;
  min-width: 0;
  box-sizing: border-box;
  padding: 5px 12px;
  border: 0.5px solid rgba(0, 0, 0, 0.18);
  border-radius: 13px;
  font-size: 13px;
  line-height: 1.4;
  resize: none;
  overflow-y: auto;
  min-height: 30px;
  max-height: 96px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.ai-task::placeholder { color: var(--text-3); }
.ai-task:focus {
  outline: none;
  border-color: rgba(0, 0, 0, 0.28);
  box-shadow: none;
}
/* 发送圆钮：蓝底白色上箭头（iMessage 发送键） */
.ai-send-btn {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  margin-bottom: 2px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.12s ease, transform 0.1s ease;
}
.ai-send-btn:hover { background: var(--accent-hover); }
.ai-send-btn:active { transform: scale(0.92); }
.ai-send-btn svg { width: 15px; height: 15px; display: block; }
/* 停止钮：同款圆钮，灰底方点 */
.ai-send-btn.stop { background: var(--seg-bg); color: var(--text-2); }
.ai-send-btn.stop:hover { background: var(--separator-strong); color: var(--text); }

/* 3. 对话流（iMessage 会话区：白底 + 气泡 + 附件卡片 + 过程折叠） */
.ai-trace {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 8px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 0;
}
/* 时间分隔（iMessage 顶部居中小灰字：1月15日 周四 15:57） */
.ai-msg-ts {
  align-self: center;
  text-align: center;
  font-size: 11px;
  color: var(--text-3);
  padding: 2px 8px;
  margin: 6px 0 10px;
  letter-spacing: 0.01em;
  animation: ai-fade-in 0.18s ease;
  user-select: none;
}
/* 已读回执（iMessage 「已读」小灰字，右对齐） */
.ai-read-receipt {
  align-self: flex-end;
  font-size: 11px;
  color: var(--text-3);
  margin: 3px 2px 0 0;
  animation: ai-fade-in 0.25s ease;
  user-select: none;
}
/* AI 空状态（2026-09-05 人性化）：标题 + 引导语 + 建议提示条 */
.ai-trace-empty { color: var(--text-3); text-align: center; padding: 26px 10px 20px; }
.ai-empty-title { color: var(--text); font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.ai-empty-sub { font-size: 12px; line-height: 1.6; margin: 0 auto 14px; max-width: 240px; }
.ai-suggest-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.ai-suggest-chip {
  border: 1px solid var(--separator-strong);
  background: var(--toolbar-bg);
  color: var(--text-2);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.ai-suggest-chip:hover { border-color: var(--accent); color: var(--accent); }
.ai-suggest-chip:active { background: var(--accent-fill); }

/* AI 配色徽章（插件注入 #ai-render-sync）：低调信息条；仅「未同步」警示着色 */
.ai-render-sync {
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-3);
  padding: 5px 12px 4px;
  border-bottom: 1px dashed var(--separator);
}
.ai-render-sync.is-locked { color: var(--text-2); }
.ai-render-sync.is-unsynced { color: var(--danger); border-bottom-color: var(--danger); }
.ai-trace-row {
  font-size: 12px;
  line-height: 1.5;
  padding: 5px 8px;
  margin-bottom: 4px;
  border-radius: var(--r-row);
  word-break: break-word;
  animation: ai-fade-in 0.18s ease;
}
@keyframes ai-fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}
.ai-trace-row.info { color: var(--text-2); }
.ai-trace-row.thinking { color: var(--text-3); font-style: italic; }
.ai-trace-row.tool {
  color: var(--text-2);
  background: var(--hover);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
}
.ai-trace-row.snapshot {
  color: #0099A8;
  background: rgba(0, 229, 255, 0.08);
  cursor: pointer;
}
.ai-trace-row.snapshot:hover { background: rgba(0, 229, 255, 0.16); }
.ai-trace-row.observation { color: var(--text-2); background: var(--hover); }
.ai-trace-row.annotation {
  color: #B8860B;
  background: rgba(255, 215, 0, 0.1);
}
.ai-trace-row.bubble {
  color: var(--text);
  background: var(--accent-fill);
  border-left: 3px solid var(--accent);
}
.ai-trace-row.finished {
  color: #1a7d34;
  background: rgba(40, 167, 69, 0.1);
  border-left: 3px solid #28a745;
}
.ai-trace-row.error {
  color: #c0392b;
  background: rgba(231, 76, 60, 0.1);
  border-left: 3px solid #e74c3c;
}

/* 会话区子元素间距：组间 8px，同侧连发（.grp）2px，回执/时间戳各自微调 */
.ai-trace > * + * { margin-top: 8px; }
.ai-trace > .ai-msg-ts { margin-top: 14px; }
.ai-trace > .ai-msg-ts:first-child { margin-top: 0; }
.ai-trace > .ai-chat-bubble.grp { margin-top: 2px; }
.ai-trace > .ai-read-receipt { margin-top: 3px; }

/* iOS Messages 气泡：user 右蓝、assistant 左灰；.tail 画 iMessage 尾巴 */
.ai-chat-bubble {
  position: relative;
  font-size: 13px;
  line-height: 1.4;
  padding: 7px 11px;
  border-radius: 13px;
  max-width: 82%;
  word-break: break-word;
  animation: ai-fade-in 0.18s ease;
  align-self: flex-start;
  font-family: var(--font);
}
.ai-chat-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  white-space: pre-wrap;
}
.ai-chat-bubble.assistant {
  align-self: flex-start;
  background: #e9e9eb;
  color: var(--text);
  white-space: pre-wrap;
}
/* 尾巴：同色块延伸 + 会话底色挖弧（经典 iMessage 尾巴画法，缩小匹配 13px 气泡） */
.ai-chat-bubble.user.tail::before {
  content: "";
  position: absolute;
  z-index: 0;
  bottom: 0;
  right: -5px;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-bottom-left-radius: 11px;
}
.ai-chat-bubble.user.tail::after {
  content: "";
  position: absolute;
  z-index: 1;
  bottom: 0;
  right: -5px;
  width: 6px;
  height: 14px;
  background: #fff;
  border-bottom-left-radius: 8px;
}
.ai-chat-bubble.assistant.tail::before {
  content: "";
  position: absolute;
  z-index: 0;
  bottom: 0;
  left: -5px;
  width: 14px;
  height: 14px;
  background: #e9e9eb;
  border-bottom-right-radius: 11px;
}
.ai-chat-bubble.assistant.tail::after {
  content: "";
  position: absolute;
  z-index: 1;
  bottom: 0;
  left: -5px;
  width: 6px;
  height: 14px;
  background: #fff;
  border-bottom-right-radius: 8px;
}
.ai-chat-bubble.assistant.ai-md {
  white-space: normal;
}
.ai-chat-bubble.ai-md > *:first-child { margin-top: 0; }
.ai-chat-bubble.ai-md > *:last-child { margin-bottom: 0; }
.ai-chat-bubble.ai-md p {
  margin: 0 0 0.55em;
  line-height: 1.45;
}
.ai-chat-bubble.ai-md h1,
.ai-chat-bubble.ai-md h2,
.ai-chat-bubble.ai-md h3 {
  margin: 0.65em 0 0.35em;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}
.ai-chat-bubble.ai-md h1 { font-size: 1.12em; }
.ai-chat-bubble.ai-md h2 { font-size: 1.06em; }
.ai-chat-bubble.ai-md h3 { font-size: 1.0em; }
.ai-chat-bubble.ai-md ul,
.ai-chat-bubble.ai-md ol {
  margin: 0.3em 0 0.55em;
  padding-left: 1.35em;
}
.ai-chat-bubble.ai-md li {
  margin: 0.18em 0;
  line-height: 1.45;
}
.ai-chat-bubble.ai-md blockquote {
  margin: 0.4em 0 0.55em;
  padding: 0.15em 0 0.15em 0.75em;
  border-left: 3px solid rgba(0, 0, 0, 0.12);
  color: var(--text-2);
}
.ai-chat-bubble.ai-md code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: rgba(0, 0, 0, 0.06);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.ai-chat-bubble.ai-md .ai-md-pre {
  margin: 0.45em 0 0.55em;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.05);
  overflow-x: auto;
}
.ai-chat-bubble.ai-md .ai-md-pre code {
  background: transparent;
  padding: 0;
  font-size: 0.86em;
  line-height: 1.4;
  white-space: pre;
}
.ai-chat-bubble.ai-md a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ai-chat-bubble.ai-md strong { font-weight: 600; }
.ai-chat-bubble.ai-md em { font-style: italic; }

/* iMessage 「正在输入」三点气泡 */
.ai-chat-thinking {
  position: relative;
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 9px 11px;
  border-radius: 13px;
  background: #e9e9eb;
  animation: ai-fade-in 0.18s ease;
}
.ai-chat-thinking::before {
  content: "";
  position: absolute;
  z-index: 0;
  bottom: 0;
  left: -5px;
  width: 14px;
  height: 14px;
  background: #e9e9eb;
  border-bottom-right-radius: 11px;
}
.ai-chat-thinking::after {
  content: "";
  position: absolute;
  z-index: 1;
  bottom: 0;
  left: -5px;
  width: 6px;
  height: 14px;
  background: #fff;
  border-bottom-right-radius: 8px;
}
.ai-chat-thinking .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #98989d;
  animation: ai-typing-blink 1.2s infinite ease-in-out;
}
.ai-chat-thinking .dot:nth-child(2) { animation-delay: 0.2s; }
.ai-chat-thinking .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-typing-blink {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

/* 低调重连提示 */
.ai-reconnect {
  align-self: center;
  text-align: center;
  font-size: 11px;
  line-height: 1.3;
  color: var(--text-3);
  opacity: 0.72;
  padding: 2px 8px;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  animation: ai-fade-in 0.15s ease;
  user-select: none;
}

/* 状态行（居中） */
.ai-status {
  align-self: center;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  padding: 4px 10px;
  max-width: 95%;
  animation: ai-fade-in 0.18s ease;
}
.ai-status.finished {
  color: #1a7d34;
  font-weight: 500;
  background: rgba(40, 167, 69, 0.1);
  border-radius: 8px;
}
.ai-status.paused {
  color: #b36b00;
  background: rgba(255, 193, 7, 0.12);
  border-radius: 8px;
}
.ai-status.error {
  color: #c0392b;
  background: rgba(231, 76, 60, 0.1);
  border-radius: 8px;
}
.ai-status.info { color: var(--text-3); }

/* OpenAI 风格工具调用 */
.ai-tool-call {
  align-self: flex-start;
  max-width: 92%;
  margin: 1px 0;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.03);
  animation: ai-fade-in 0.15s ease;
}
.ai-tool-call > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 10px;
  user-select: none;
}
.ai-tool-call > summary::-webkit-details-marker { display: none; }
.ai-tool-call > summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--text-3);
  flex-shrink: 0;
  align-self: center;
  transition: transform 0.12s ease;
}
.ai-tool-call[open] > summary::before {
  transform: rotate(180deg);
}
.ai-tool-name {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  font-family: var(--mono);
  white-space: nowrap;
}
.ai-tool-brief {
  font-size: 12px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.ai-tool-body {
  padding: 0 10px 8px 22px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--text-3);
  font-family: var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
}

/* 对话内嵌附件（无边框，替代旧卡片） */
.ai-attach {
  align-self: flex-start;
  max-width: 88%;
  margin: 2px 0;
  padding: 8px 12px;
  border-radius: 14px;
  border: none;
  background: rgba(0, 0, 0, 0.04);
  animation: ai-fade-in 0.18s ease;
  word-break: break-word;
}
.ai-attach-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}
.ai-attach-body {
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-2);
  margin-top: 3px;
  white-space: pre-wrap;
}
/* 标注卡片正文折叠：正文常与紧邻的观察段重复，默认收 2 行，角标展开 */
.ai-attach.annotation .ai-attach-body {
  position: relative;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}
.ai-attach.annotation .ai-attach-body.expanded {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}
.ai-clamp-hint {
  position: absolute;
  right: 0;
  bottom: 0;
  padding: 0 4px 0 14px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--accent);
  background: linear-gradient(90deg, rgba(38, 46, 61, 0), rgba(38, 46, 61, 0.95) 34%);
  cursor: pointer;
  user-select: none;
}
/* AI 配置来源提示：owner=平台托管说明 / user=当前生效来源（§5.1.2） */
.ai-config-source-hint {
  font-size: 11.5px;
  color: var(--text-3);
  line-height: 1.45;
  margin: 2px 0 6px;
}
.ai-attach-sub {
  font-size: 11.5px;
  color: var(--text-3);
  margin-top: 4px;
  line-height: 1.4;
}
.ai-attach-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
/* 碎碎念（观察/已判读总结）：不像卡片、不可点，读起来像随手记的一句 */
.ai-mutter {
  padding: 1px 4px;
  border-radius: 6px;
  background: transparent;
  cursor: default;
}
.ai-mutter .ai-attach-title {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-3);
}
.ai-mutter .ai-attach-body {
  font-style: italic;
  font-size: 12.5px;
  color: var(--text-2);
}
.ai-attach.snapshot {
  background: rgba(0, 122, 255, 0.05);
  cursor: pointer;
  color: var(--accent);
}
.ai-attach.snapshot:hover { background: rgba(0, 122, 255, 0.1); }
.ai-attach.snapshot .ai-attach-title { color: var(--accent); font-weight: 500; }
.ai-attach.annotation {
  background: rgba(255, 149, 0, 0.08);
  cursor: pointer;
}
.fork-chat-stream .ai-mutter { padding: 1px 3px; }

.fork-chat-stream {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.fork-chat-stream .ai-attach { padding: 6px 10px; max-width: 96%; }
.fork-chat-stream .ai-attach-title { font-size: 12px; }
.fork-chat-stream .ai-attach-body { font-size: 12px; }
.fork-chat-stream .ai-chat-bubble { font-size: 13px; max-width: 92%; padding: 7px 11px; }
.fork-chat-stream .ai-tool-call { max-width: 96%; }

/* 手机端：AI 面板贴底显示 */
@media (max-width: 768px) {
  .ai-panel {
    right: 8px; left: 8px; top: auto;
    bottom: calc(var(--tbb-bar-h) + 8px + var(--safe-bottom));
    width: auto; max-height: 60%;
    animation: sheet-up 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
  }
  body.ctx-on .ai-panel {
    bottom: calc(var(--tbb-bar-h) + var(--tbb-ctx-h) + 8px + var(--safe-bottom));
  }
}


/* =========================================================================
   AI 批注式对话（fork）
   ========================================================================= */
/* 标注面板行的 fork/branch 动作按钮（P1-6：图标+短文字小按钮，hover 高亮）
   基类复用 .ai-op（26×26 圆角），文字模式放宽为自适应宽度。 */
.anno-item .ai-op.ai-fork,
.anno-item .ai-op.ai-branch {
  width: auto;
  min-width: 0;
  padding: 0 8px;
  gap: 3px;
  font-size: 11px;
  font-weight: 500;
}
.ai-op .ai-act-ic { font-size: 12px; line-height: 1; }
.ai-op .ai-act-tx { white-space: nowrap; }
.anno-item .ai-op.ai-fork:hover { color: #7b5cff; background: rgba(123, 92, 255, 0.12); }
.anno-item .ai-op.ai-branch:hover { color: #0a9396; background: rgba(10, 147, 150, 0.12); }

/* Stage 3c-1：AI 标注审核（接受/驳回）按钮与状态徽章 */
.anno-item .ai-op.ai-review-accept { color: #0a9396; }
.anno-item .ai-op.ai-review-accept:hover { background: rgba(10, 147, 150, 0.14); }
.anno-item .ai-op.ai-review-reject { color: #c0392b; }
.anno-item .ai-op.ai-review-reject:hover { background: rgba(192, 57, 43, 0.14); }
.anno-review-badge {
  display: inline-flex; align-items: center; font-size: 9px; font-weight: 600;
  line-height: 1; padding: 2px 5px; margin-left: 4px; border-radius: 4px;
  vertical-align: middle;
}
.anno-review-badge.accepted { color: #0a9396; background: rgba(10, 147, 150, 0.16); }
.anno-review-badge.rejected { color: #c0392b; background: rgba(192, 57, 43, 0.16); }

/* AI 轨迹流里标注行的 fork/branch chip（对话内嵌卡片用） */
.ai-trace-row.annotation { display: flex; align-items: center; gap: 6px; }
.ai-action-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border: 0.5px solid var(--separator-strong);
  border-radius: 12px;
  background: #fff;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  cursor: pointer;
  line-height: 1.4;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.ai-action-chip .ai-act-ic { font-size: 12px; line-height: 1; }
.ai-action-chip .ai-act-tx { white-space: nowrap; }
.ai-action-chip.ai-fork:hover { color: #7b5cff; border-color: rgba(123, 92, 255, 0.45); background: rgba(123, 92, 255, 0.08); }
.ai-action-chip.ai-branch:hover { color: #0a9396; border-color: rgba(10, 147, 150, 0.45); background: rgba(10, 147, 150, 0.08); }

/* 就地展开的 fork 对话块（标注面板内） */
.fork-chat {
  margin: 6px 6px 8px 6px;
  background: #fff;
  border: 0.5px solid var(--separator-strong);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.fork-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  padding: 6px 8px;
  border-bottom: 0.5px solid var(--separator-weak);
}
.fork-chat-head .icon-btn { width: 20px; height: 20px; font-size: 12px; }
.fork-chat-stream {
  max-height: 220px;
  overflow-y: auto;
  padding: 6px 8px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.fork-chat-stream .ai-trace-row { padding: 3px 2px; }
.fork-chat-input {
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  border-top: 0.5px solid var(--separator-weak);
}
.fork-chat-input input {
  flex: 1;
  min-width: 0;
  border: 0.5px solid var(--separator-strong);
  border-radius: var(--r-input);
  padding: 4px 8px;
  font-size: 12px;
}
/* 标注已删除/归档：fork 对话只读（P1-4：JS 与 CSS 类名统一为 fork-readonly）。
   输入与发送钮隐藏；整块轻灰底提示归档态，但内容（历史）仍可读。 */
.fork-chat.fork-readonly .fork-chat-input { display: none; }
.fork-chat.fork-readonly { background: #f6f6f6; }
.fork-chat.fork-readonly .fork-chat-head { color: var(--text-3); }

/* =========================================================================
   Demo 只读运行模式（与正式版共用外壳，仅额外展示徽章 / 额度 / 登录）
   ========================================================================= */
.demo-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  border: 1px solid rgba(0, 122, 255, 0.35);
  border-radius: 6px;
  padding: 1px 6px;
  line-height: 1.4;
}
.preview-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px;
  background: #fff6d6;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 13px;
  color: #6b5a00;
  z-index: 20;
}
.preview-banner[hidden] { display: none !important; }
/* 侧栏顶部紧凑徽章：仅移动端显示（标题栏在 360px 级视口放不下徽章，
   见文件末尾 @media (max-width: 760px) 的挪移规则；桌面隐藏避免与标题栏重复） */
.demo-badge-side { display: none; }
.header-login-link {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.header-login-link:hover { text-decoration: underline; }
.demo-quota-chip {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text);
  background: var(--accent-fill);
  border-radius: var(--r-row);
  padding: 8px 10px;
}
.demo-quota-hint {
  margin: 8px 12px 0;
  font-size: 11px;
  color: var(--text-2);
  line-height: 1.5;
}
/* Demo 面板级状态条（demo.html：#ai-status 是 .demo-ai-panel 的直接子元素）。
   §11 Bug B：旧版写成通用 `.ai-status { min-height: 0 }`，会让主轨迹
   .ai-trace（flex column）里的状态行被压缩、长文本溢出盖住下一条消息——
   现收窄为仅 Demo 面板子元素生效，不再覆盖主轨迹组件。 */
.demo-ai-panel > .ai-status {
  margin: 6px 12px 0;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.6;
  min-height: 0;
}
.ai-status.error { color: var(--danger); }
.ai-status a { color: var(--accent); }
/* §11 Bug B 防御：主轨迹内的状态行不参与 flex 收缩，保持内容自然高度
   （长总结在场时状态行/短状态也不得压扁、溢出覆盖下一条消息）。 */
.ai-trace > .ai-status {
  flex-shrink: 0;
  min-height: auto;
}
.ai-panel-header .ai-state {
  margin-left: auto;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
}
.demo-disclaimer {
  font-size: 11px;
  color: var(--text-2);
  line-height: 1.5;
  margin: 0 0 8px;
}
.demo-ai-panel { display: flex; }
.ai-send-btn:disabled { opacity: 0.45; cursor: default; }

/* Demo 轨迹复用正式面板气泡语义（测试仍断言 ai-msg / ai-row） */
.ai-trace .ai-msg {
  font-size: 13px;
  line-height: 1.4;
  padding: 7px 11px;
  border-radius: 13px;
  max-width: 82%;
  word-break: break-word;
  white-space: pre-wrap;
}
.ai-trace .ai-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
}
.ai-trace .ai-msg.agent {
  align-self: flex-start;
  background: #e9e9eb;
  color: var(--text);
}
.ai-trace .ai-row {
  font-size: 12px;
  color: var(--text-2);
  padding: 2px 4px;
}
.ai-trace .ai-row.error { color: var(--danger); }
.ai-trace .ai-obs {
  align-self: flex-start;
  background: #f0f7f0;
  border: 1px solid rgba(52, 199, 89, 0.35);
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 12.5px;
  color: var(--text);
}
.ai-trace .ai-obs b { font-size: 12px; }
/* 观察卡：viewport 小结与 region 观察区；可点选的 region 卡选中后加边框 */
.ai-trace .ai-obs .ai-obs-note {
  margin-top: 2px;
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.4;
  word-break: break-word;
}
.ai-trace .ai-obs .ai-obs-scope {
  display: inline-block;
  margin-top: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  background: rgba(52, 199, 89, 0.12);
  color: #1f7a37;
}
.ai-trace .ai-obs.obs-viewport .ai-obs-scope {
  background: #ececec;
  color: var(--text-2);
}
.ai-trace .ai-obs.obs-region[style*="pointer"] { user-select: none; }
.ai-trace .ai-obs.selected {
  border-color: rgba(52, 199, 89, 0.9);
  box-shadow: 0 0 0 2px rgba(52, 199, 89, 0.2);
}

.demo-unavailable {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px 24px;
  text-align: center;
}
.demo-unavailable h1 { font-size: 19px; font-weight: 600; }
.demo-unavailable p { font-size: 13px; color: var(--text-2); line-height: 1.7; max-width: 460px; }
.demo-unavailable .actions { display: flex; gap: 10px; margin-top: 8px; }
.demo-unavailable .btn {
  display: inline-block;
  height: 40px;
  line-height: 40px;
  padding: 0 18px;
  text-decoration: none;
}
.demo-unavailable-footer { font-size: 12px; color: var(--text-2); margin-top: 12px; }

@media (max-width: 760px) {
  .header-register-link { display: none; }
  /* 只读徽章不在标题栏隐藏消失：标题栏（☰ + 切片名 + zoom 徽章 + 登录链接 +
     语言钮）在 375/360px 视口放不下徽章，改在侧栏顶部与额度 chip 同行显示，
     保证 Demo 页任何视口都有明确只读标识 */
  .title-group .demo-badge { display: none; }
  .demo-sidebar-top {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }
  .demo-sidebar-top .demo-quota-chip { flex: 1; min-width: 0; }
  /* 窄屏 Demo：搜索框独占一行（徽章 + 额度 chip 一行放不下三个元素） */
  .demo-sidebar-top .slide-search { flex: 1 0 100%; order: 3; }
  .demo-badge-side {
    display: inline-flex;
    flex-shrink: 0;
    font-size: 10px;
    padding: 0 4px;
  }
}


/* =========================================================================
   修改我的密码弹窗（账户系统批次 A docs §7.1/§8.1）
   复用 picker-mask/picker-dialog 骨架；侧栏底部的入口与退出登录同风格。
   ========================================================================= */
.sidebar-bottom .changepw-link {
  display: block;
  margin-bottom: 6px;
}
.changepw-body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.changepw-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-2);
}
.changepw-field input {
  height: 30px;
  border: 1px solid var(--separator);
  border-radius: var(--r-btn, 8px);
  padding: 0 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
}
.changepw-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}
.changepw-hint {
  font-size: 11px;
  color: var(--text-3, var(--text-2));
  line-height: 1.5;
}
.changepw-error {
  font-size: 12px;
  color: var(--danger);
  background: var(--danger-tint);
  border-radius: var(--r-btn, 8px);
  padding: 6px 10px;
}

/* -----------------------------------------------------------------------
   viewer 画质档（image-transport-upgrade §3.3）：标准/精细分段与荧光保真标识。
   只做展示：不向产品界面暴露 q、采样、cache key 等实现细节。
   ----------------------------------------------------------------------- */
.viewer-quality-host { display: inline-flex; flex-shrink: 0; }
.viewer-quality-host[hidden] { display: none; }
.viewer-quality-control {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  background: var(--surface-2, rgba(255, 255, 255, 0.06));
  border-radius: 8px;
  padding: 2px;
}
.viewer-quality-btn {
  border: none;
  background: transparent;
  color: var(--text-2, #cfd4da);
  font: inherit;
  font-size: 12px;
  line-height: 1;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.viewer-quality-btn:hover { color: var(--text-1, #fff); }
.viewer-quality-btn.active {
  background: var(--accent, #4d7cfe);
  color: #fff;
}
.viewer-quality-badge {
  font-size: 12px;
  color: var(--text-2, #cfd4da);
  background: var(--surface-2, rgba(255, 255, 255, 0.06));
  border-radius: 8px;
  padding: 4px 10px;
  flex-shrink: 0;
  white-space: nowrap;
  cursor: default;
  line-height: 1.2;
}
