:root {
  /* 浅蓝留白风格：三层信息 = 深蓝主信息 / 灰蓝说明 / 亮蓝操作；三档圆角 = 卡片 12 / 按钮 10 / 浮层 16 */
  --bg: #eef3fa;
  --panel: #ffffff;
  --panel-2: #f5f8fd;
  --glass: rgba(255, 255, 255, .86);
  --line: #e2e9f4;
  --line-2: #cfdbee;
  --fg: #1a2b4c;
  --fg-dim: #7b8aa6;
  --accent: #2f6bff;
  --accent-soft: #eaf1ff;
  --accent-grad: linear-gradient(180deg, #4f86ff, #2f6bff);
  --accent-2: #e07b00;
  --cur: #ff8c1a;
  --cur-soft: #fff3e6;
  --r-card: 12px;
  --r-btn: 10px;
  --r-pop: 16px;
  --shadow-card: 0 2px 6px rgba(35, 74, 150, .05), 0 8px 24px rgba(35, 74, 150, .07);
  --shadow-btn: 0 4px 12px rgba(47, 107, 255, .28);
  --shadow-pop: 0 16px 48px rgba(35, 74, 150, .18);
  --gap: 10px;
  --topbar-h: 48px;
  --left-w: 300px;
  --right-w: 320px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { height: 100dvh; }   /* iOS 地址栏伸缩时按实际可见高度排版，底部工具条不被盖住（不支持 dvh 的浏览器用上一行） */
body {
  background: var(--bg) radial-gradient(1200px 600px at 80% -10%, #dfe9fb 0, transparent 60%); color: var(--fg);
  font: 13px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app {
  height: 100%;
  display: grid;
  grid-template-columns: var(--left-w) 1fr var(--right-w);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) auto;
  gap: var(--gap); padding: var(--gap);
  grid-template-areas:
    "top top top"
    "left stage right"
    "status status status";
}

/* ---------- 顶栏 ---------- */
#topbar {
  grid-area: top; display: flex; align-items: center; gap: 10px;
  padding: 0 10px 0 14px; background: var(--glass); border: 1px solid #fff; border-radius: var(--r-card);
  box-shadow: var(--shadow-card); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
#topbar h1 { font-size: 15px; font-weight: 700; margin: 0; white-space: nowrap; letter-spacing: .2px; }
#topbar h1 small { color: var(--fg-dim); font-weight: 400; margin-left: 6px; }
.spacer { flex: 1; }
#toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sep { width: 1px; height: 22px; background: var(--line); }

button, select, input[type="search"] {
  background: var(--panel); color: var(--fg);
  border: 1px solid var(--line-2); border-radius: var(--r-btn);
  padding: 6px 12px; font: inherit; cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s, color .15s;
}
button:hover, select:hover { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.active, .tool.active {
  background: var(--accent-grad); border-color: transparent; color: #fff; font-weight: 600; box-shadow: var(--shadow-btn);
}
button.active:hover { color: #fff; }
input[type="search"] { cursor: text; background: var(--panel-2); }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.icon-btn { padding: 4px 8px; }
#btn-tree, #btn-props, .only-narrow { display: none; }

/* ---------- 面板 ---------- */
.panel {
  background: var(--panel); display: flex; flex-direction: column; min-height: 0;
  border: 1px solid #fff; border-radius: var(--r-card); box-shadow: var(--shadow-card); overflow: hidden;
}
#left { grid-area: left; }
#right { grid-area: right; }
.panel-head { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.panel-head strong { font-size: 14px; }
.panel-head .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.panel-body { overflow: auto; padding: 8px 10px; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; }
.panel-foot { padding: 10px 12px; border-top: 1px solid var(--line); color: var(--fg-dim); font-size: 12px; }
#search { width: 100%; cursor: text; }
.hint { color: var(--fg-dim); font-size: 12px; min-height: 16px; }
.chk { display: inline-flex; align-items: center; gap: 4px; color: var(--fg-dim); cursor: pointer; }

/* ---------- 构件树 ---------- */
.node { user-select: none; }
.node-row {
  display: flex; align-items: center; gap: 5px;
  padding: 3px 6px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.node-row:hover { background: var(--panel-2); }
.node-row.sel { background: var(--accent-soft); color: var(--accent); }
.node-row.hidden-item .label { color: #b3bfd2; text-decoration: line-through; }
.twist { width: 14px; text-align: center; color: var(--fg-dim); flex: 0 0 14px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 10px; border: 1px solid #0002; }
.eye { width: 18px; flex: 0 0 18px; text-align: center; color: var(--fg-dim); }
.label { overflow: hidden; text-overflow: ellipsis; }
.meta { color: var(--fg-dim); font-size: 11px; margin-left: auto; padding-left: 8px; }
.mark { color: var(--accent-2); }
.children { margin-left: 14px; display: none; }
.node.open > .children { display: block; }

/* ---------- 3D ---------- */
/* min-height:0 + overflow:hidden：否则 canvas 的像素尺寸会当成内容高度撑开网格行，
   手机从竖屏转横屏时整块画面被挤出屏幕（实测 390x844 -> 844x390 一片空白） */
#stage {
  grid-area: stage; position: relative; min-width: 0; min-height: 0; overflow: hidden;
  border-radius: var(--r-card); border: 1px solid #fff; box-shadow: var(--shadow-card);
  background: radial-gradient(120% 90% at 50% 0%, #ffffff 0%, #eaf1fb 55%, #dde7f6 100%);
}
#canvas { display: block; width: 100%; height: 100%; touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
#hud {
  position: absolute; left: 10px; bottom: 10px; pointer-events: none;
  font-variant-numeric: tabular-nums; font-size: 12px; color: var(--fg-dim);
  background: var(--glass); padding: 4px 10px; border-radius: 8px; box-shadow: var(--shadow-card);
}
.tool-hint {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%);
  background: var(--fg); color: #fff; padding: 6px 14px; border-radius: 999px; box-shadow: var(--shadow-pop);
  font-size: 12px; pointer-events: none; opacity: 0; transition: opacity .2s;
}
.tool-hint.show { opacity: 1; }

/* ---------- 属性 / 测距 / 剖切 ---------- */
table.props { width: 100%; border-collapse: collapse; }
table.props th, table.props td { text-align: left; padding: 5px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.props th { color: var(--fg-dim); font-weight: 400; width: 38%; }
table.props td { font-variant-numeric: tabular-nums; word-break: break-all; }
.empty { color: var(--fg-dim); padding: 8px 4px; }
.warn { color: var(--accent-2); font-size: 12px; margin-top: 6px; }

.measure-list, .section-ui { display: none; border-top: 1px solid var(--line); flex: 0 0 auto; max-height: 45%; }
.measure-list.show, .section-ui.show { display: block; }
.m-item { border-bottom: 1px solid var(--line); padding: 5px 2px; }
.m-item .m-d { font-weight: 600; font-variant-numeric: tabular-nums; }
.m-item .m-c { color: var(--fg-dim); font-size: 11px; font-variant-numeric: tabular-nums; }
.m-item button { padding: 1px 6px; font-size: 11px; float: right; }
.sec-row { display: flex; align-items: center; gap: 6px; margin: 6px 0; }
.sec-row label { width: 56px; color: var(--fg-dim); }
.sec-row input[type="range"] { flex: 1; }
.sec-row .val { width: 74px; text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }

/* ---------- 状态栏 ---------- */
#status {
  grid-area: status; background: transparent;
  padding: 0 6px; margin-top: calc(-1 * var(--gap) / 2); color: var(--fg-dim); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- 抽屉遮罩（只在窄屏出现）---------- */
#backdrop { display: none; }
/* 要压过 .panel-head .row 的 display:flex，否则宽屏也会露出抽屉标题栏 */
.panel-head .drawer-bar { display: none; align-items: center; }
.drawer-bar .spacer { display: block; flex: 1; }

/* ---------- 平板 / 手机 ---------- */
@media (max-width: 1100px) {
  :root { --left-w: 260px; --right-w: 280px; }
}
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; grid-template-areas: "top" "stage" "status"; --gap: 6px; }
  #btn-tree, #btn-props, .only-narrow { display: inline-block; }
  /* 抽屉叠在 3D 区那一格上：上下边跟着顶栏和状态栏走，不用写死状态栏高度 */
  .panel {
    align-self: stretch; width: min(86vw, 340px); min-height: 0;
    z-index: 20; box-shadow: var(--shadow-pop); display: none; border-radius: var(--r-pop);
  }
  #left { grid-area: stage; justify-self: start; }
  #right { grid-area: stage; justify-self: end; }
  .panel.open { display: flex; animation: slide-in .16s ease-out; }
  #left.open { animation-name: slide-in-left; }
  @keyframes slide-in-left { from { transform: translateX(-12px); opacity: .6 } to { transform: none; opacity: 1 } }
  @keyframes slide-in { from { transform: translateX(12px); opacity: .6 } to { transform: none; opacity: 1 } }
  #backdrop.show {
    display: block; position: absolute; inset: 0;
    background: rgba(26, 43, 76, .22); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); z-index: 15;
  }
  .panel-head .drawer-bar { display: flex; }
  #left-close, #right-close { font-size: 12px; }
  /* 窄屏顶栏只有一行高：工具栏不换行，改成横向滚动，避免按钮被切掉 */
  #toolbar {
    flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
    padding: 0 2px; flex: 1 1 auto;
    justify-content: flex-start;   /* 从左排：先露出选择/测距/坐标/剖切这些主工具 */
    scroll-snap-type: x proximity;
  }
  #toolbar > * { scroll-snap-align: start; }
  #toolbar::-webkit-scrollbar { display: none; }
  #toolbar .tool, #toolbar button, #toolbar select { padding: 6px 10px; flex: 0 0 auto; }
  #toolbar select { max-width: 132px; }
  #topbar { gap: 6px; padding: 0 6px; }
  #topbar h1 { font-size: 13px; flex: 0 0 auto; }
  #topbar h1 small { display: none; }
  .spacer { display: none; }
}
@media (max-width: 620px) {
  /* 屏幕太窄时标题让位给工具栏，分段名在构件树根节点和标签页标题里都有 */
  #topbar h1 { display: none; }
  /* 装配模式多了「测距」，375px 宽的手机上一排放得下：收紧间距和按钮内边距 */
  #topbar { gap: 6px; padding: 0 6px; }
  #toolbar { gap: 4px; }
  #topbar button { padding-left: 7px; padding-right: 7px; }
}
@media (pointer: coarse) {
  button, select { min-height: 34px; }
  .node-row { padding: 6px 4px; }
}

/* ---------- 画布上的标签 ---------- */
.lbl {
  position: absolute; left: 0; top: 0; pointer-events: none;
  background: var(--glass); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 2px 8px; box-shadow: var(--shadow-card); font-size: 12px; font-variant-numeric: tabular-nums;
  white-space: nowrap; z-index: 5;
}
.lbl-dist { color: var(--accent); border-color: #2f6bff55; font-weight: 700; }
.lbl-coord { color: var(--accent-2); border-color: #e07b0055; }

/* ---------- 装配模式 ---------- */
.asm-only { display: none !important; }
#app.asm-mode .asm-only { display: revert !important; }
#app.asm-mode .tree-only { display: none !important; }
#app.asm-mode #asm-panel { display: flex !important; flex-direction: column; gap: 8px; }
#app.asm-mode #asm-bar { display: flex !important; }
.asm-ctrl { display: flex; flex-direction: column; gap: 6px; }
.asm-ov { font-weight: 600; }
.asm-list { display: flex; flex-direction: column; gap: 2px; }
.asm-step {
  display: grid; grid-template-rows: auto auto; column-gap: 6px;
  padding: 6px 8px; border-radius: var(--r-btn); cursor: pointer; border: 1px solid transparent;
}
.asm-step:hover { background: var(--panel-2); }
.asm-no {
  grid-row: 1 / 3; align-self: center; width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel-2); border: 1px solid var(--line); font-weight: 700; font-variant-numeric: tabular-nums;
}
.asm-name { font-weight: 600; }
.asm-meta { color: var(--fg-dim); font-size: 11px; }
.asm-step.done .asm-no { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }
.asm-step.done .asm-name { color: var(--fg-dim); }
.asm-step.cur { background: var(--cur-soft); border-color: var(--cur); }
.asm-step.cur .asm-no { background: var(--cur); color: #fff; border-color: var(--cur); }
.asm-src { margin-top: 4px; }

#asm-bar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--r-pop);
  background: var(--glass); border: 1px solid #fff; box-shadow: var(--shadow-pop);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  touch-action: pan-y; user-select: none; max-width: calc(100% - 20px);
}
#asm-bar button { min-width: 48px; min-height: 42px; font-size: 16px; }
.asm-cur { display: flex; flex-direction: column; align-items: center; min-width: 120px; padding: 0 6px; }
.asm-idx { color: var(--cur); font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.asm-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
#app.asm-mode #hud { bottom: 80px; }

.asm-balloon {
  position: absolute; left: 0; top: 0; z-index: 6; cursor: pointer; white-space: nowrap;
  --c: #ff8c1a;
  background: #fffffff2; color: var(--fg); border: 2px solid var(--c); border-radius: 14px;
  box-shadow: 0 3px 10px rgba(35, 74, 150, .16);
  padding: 1px 8px 1px 2px; font-size: 12px; line-height: 20px;
}
.asm-balloon.compact { padding: 1px 2px; }
.asm-balloon.compact span { display: none; }
.asm-balloon b {
  display: inline-block; min-width: 20px; height: 20px; border-radius: 10px; margin-right: 4px;
  background: var(--c); color: #111; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums;
}
.asm-leaders {
  position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5;
  stroke-width: 1.5; display: none;
}
#app.asm-mode .asm-leaders { display: block; }
.asm-balloon.cur { font-size: 15px; line-height: 26px; padding-right: 10px; }
.asm-balloon.compact b { margin-right: 0; }
.asm-balloon.cur b { min-width: 26px; height: 26px; border-radius: 13px; }

.asm-legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; font-size: 12px; }
.asm-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; border: 1px solid #0002; margin-right: 3px; }
table.asm-parts { margin-top: 8px; }
table.asm-parts tr[data-id] { cursor: pointer; }
table.asm-parts tr[data-id]:hover td { background: var(--panel-2); }
table.asm-parts th { width: auto; }
.asm-t { color: var(--fg-dim); font-size: 11px; margin-left: 6px; }
/* 装配模式下测距/剖切本来就停用，干脆不占顶栏位置（手机上要把 ℹ 明细按钮让出来） */
#app.asm-mode .tool[data-tool="section"] { display: none; }
#asm-bar button { white-space: nowrap; }
@media (max-width: 860px) {
  #asm-bar { bottom: 8px; gap: 4px; }
  .asm-title { max-width: 120px; }
}
@media (max-width: 620px) {
  /* 手机：步骤条铺满底部，按钮等宽好按，中间序号区自适应 */
  #asm-bar { left: 6px; right: 6px; transform: none; max-width: none; padding: 5px; gap: 5px; }
  #asm-bar button { min-width: 34px; flex: 0 1 46px; padding: 6px 0; font-size: 15px; }
  /* 文字按钮（返回 / 进入 / 总览）要 46px；◀ ▶ ⟳ 是单个符号，收窄把位置让给中间的序号 */
  #asm-bar button[data-a="prev"], #asm-bar button[data-a="next"], #asm-bar button[data-a="replay"] { flex-basis: 36px; min-width: 30px; }
  .asm-cur { flex: 1; min-width: 0; padding: 0 2px; }
  .asm-idx { white-space: nowrap; }
  .asm-title { max-width: 100%; }
  #app.asm-mode #hud { display: none; }
}
table.asm-parts td:first-child { white-space: nowrap; font-size: 11px; word-break: normal; }
/* 右侧面板头只有标题和 ×：横排，别让 × 被 flex-column 拉成一整行 */
#right .panel-head { flex-direction: row; align-items: center; justify-content: space-between; }
/* 逐层进入（docs/adr/0008）：面包屑、可进入标记、当前件脉动圈 */
#asm-bar button[hidden] { display: none; }
#asm-bar button.active { background: var(--cur-soft); border-color: var(--cur); color: var(--accent-2); box-shadow: none; }
.asm-crumbs { font-size: 13px; line-height: 1.6; word-break: break-all; }
.asm-crumbs a { color: var(--accent); text-decoration: none; }
.asm-crumbs a:hover { text-decoration: underline; }
.asm-crumbs b { color: var(--accent-2); }
/* 组立树：▶ 展开 | 序号 | 名称 + 说明 | 进入。缩进按层级 --d */
.asm-step { grid-template-columns: 16px 30px 1fr auto; padding-left: calc(4px + var(--d, 0) * 16px); }
.asm-step .asm-name { grid-column: 3; }
.asm-step .asm-meta { grid-column: 3; }
.asm-caret {
  grid-row: 1 / 3; align-self: stretch; display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--fg-dim);
}
.asm-step .asm-no { grid-column: 2; }
.asm-enter {
  grid-column: 4; grid-row: 1 / 3; align-self: center; min-width: 44px; min-height: 30px;
  padding: 0 10px; font-size: 13px; color: var(--accent); border-color: #2f6bff66; background: var(--accent-soft);
}
.asm-tree-head { font-weight: 700; padding: 4px 6px 0; }
.asm-step.other { opacity: .72; }
.asm-step.other .asm-no { width: 22px; height: 22px; font-size: 12px; }
.asm-step.path { opacity: 1; border-color: #2f6bff44; }
.asm-step.path .asm-no { border-color: var(--accent); color: var(--accent); }
.asm-enter-btn {
  width: 100%; margin-bottom: 8px; font-weight: 600; min-height: 38px;
  background: var(--accent-grad); border-color: transparent; color: #fff; box-shadow: var(--shadow-btn);
}
.asm-enter-btn:hover { color: #fff; }
.asm-pulse {
  position: absolute; left: 0; top: 0; z-index: 4; pointer-events: none; border-radius: 50%;
  border: 2px solid #ff8c1a; box-sizing: border-box; animation: asm-pulse 1.4s ease-out infinite;
}
@keyframes asm-pulse {
  0% { box-shadow: 0 0 0 0 #ff8c1acc; opacity: 1; }
  70% { box-shadow: 0 0 0 14px #ff8c1a00; opacity: .7; }
  100% { box-shadow: 0 0 0 0 #ff8c1a00; opacity: 1; }
}

/* 右键菜单 */
.ctx-menu {
  position: fixed; z-index: 50; display: flex; flex-direction: column; min-width: 150px; padding: 6px;
  background: var(--glass); border: 1px solid #fff; border-radius: var(--r-pop); box-shadow: var(--shadow-pop);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.ctx-menu[hidden] { display: none; }
.ctx-menu button { text-align: left; border: 0; background: none; padding: 8px 12px; border-radius: var(--r-btn); white-space: nowrap; }
.ctx-menu button:hover { background: var(--accent-soft); color: var(--accent); }
@media (pointer: coarse) {
  .ctx-menu button { padding: 12px 16px; font-size: 15px; }   /* 手指点得准 */
}

/* ---------- 问AI ----------
   宽屏：贴在 3D 区右侧的整高侧栏，模型在左边照常可转；窄屏：底部半屏 */
#ai-sheet {
  grid-area: right; z-index: 25; min-height: 0;
  display: flex; flex-direction: column; background: var(--panel); border: 1px solid #fff;
  border-radius: var(--r-card); box-shadow: var(--shadow-card); overflow: hidden;
  animation: ai-in .18s ease-out;
}
@keyframes ai-in { from { transform: translateX(12px); opacity: 0; } to { transform: none; opacity: 1; } }
#ai-sheet[hidden] { display: none; }
/* 宽屏：右栏加宽到 400px 换成对话（属性面板先让位，关掉 AI 就回来）；3D 区跟着缩，不被遮挡 */
@media (min-width: 861px) {
  #app.ai-open { --right-w: 400px; }
  #app.ai-open #right { visibility: hidden; }
}
.ai-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 14px; border-bottom: 1px solid var(--line); }
.ai-badge {
  flex: 0 0 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent-grad); color: #fff; font-weight: 800; font-size: 13px; letter-spacing: .5px; box-shadow: var(--shadow-btn);
}
.ai-titles { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.ai-titles strong { font-size: 15px; }
.ai-sub { color: var(--fg-dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-head .spacer { flex: 1; }
.ai-head button { padding: 5px 10px; font-size: 12px; white-space: nowrap; flex: 0 0 auto; }
.ai-head .ai-close { font-size: 16px; line-height: 1; padding: 5px 9px; }

.ai-log {
  flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px;
  overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent;
}
.ai-msg { max-width: 90%; padding: 9px 13px; border-radius: var(--r-card); line-height: 1.65; font-size: 14px; word-break: break-word; }
.ai-msg.me { align-self: flex-end; background: var(--accent-grad); color: #fff; border-bottom-right-radius: 4px; box-shadow: var(--shadow-btn); }
.ai-msg.ai { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; box-shadow: var(--shadow-card); }
.ai-msg.wait { color: var(--fg-dim); display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.ai-dots { display: inline-flex; gap: 4px; }
.ai-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: .3; animation: ai-dot 1.1s infinite ease-in-out; }
.ai-dots i:nth-child(2) { animation-delay: .15s; }
.ai-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes ai-dot { 0%, 80%, 100% { opacity: .25; transform: none; } 40% { opacity: 1; transform: translateY(-3px); } }
.ai-msg.err { color: #d93636; background: #fff5f5; border-color: #f7d4d4; }
.ai-msg ul { margin: 4px 0; padding-left: 18px; }
.ai-msg li + li { margin-top: 2px; }
.ai-ref {
  display: inline; padding: 1px 6px; margin: 0 1px; font: inherit; font-size: 13px; line-height: 1.5;
  background: var(--accent-soft); color: var(--accent); border: 1px solid #2f6bff33; border-radius: 6px; cursor: pointer;
}
.ai-ref:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.ai-did { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); color: var(--fg-dim); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.ai-did button { margin-left: auto; padding: 2px 10px; font-size: 12px; }

/* 欢迎卡 */
.ai-welcome { padding: 6px 2px 2px; }
.ai-hello { font-size: 20px; font-weight: 800; letter-spacing: .3px; }
.ai-hello-sub { color: var(--fg-dim); font-size: 13px; line-height: 1.7; margin: 6px 0 14px; }
.ai-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ai-card {
  display: grid; grid-template-columns: 34px 1fr; grid-template-rows: auto auto; column-gap: 10px; row-gap: 2px;
  text-align: left; padding: 12px; border-radius: var(--r-card); background: var(--panel); border: 1px solid var(--line);
  box-shadow: var(--shadow-card);
}
.ai-card:hover { border-color: #2f6bff66; color: inherit; transform: translateY(-1px); box-shadow: var(--shadow-pop); }
.ai-card .ai-ic {
  grid-row: 1 / 3; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
}
.ai-card b { font-size: 13.5px; }
.ai-card span:last-child { color: var(--fg-dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ai-chips { display: flex; gap: 6px; padding: 8px 14px 0; overflow-x: auto; scrollbar-width: none; }
.ai-chips::-webkit-scrollbar { display: none; }
.ai-chips button { flex: 0 0 auto; border-radius: 999px; font-size: 12px; padding: 4px 12px; color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.ai-chips button:hover { background: var(--accent); color: #fff; }
#ai-sheet.busy .ai-chips button, #ai-sheet.busy .ai-send, #ai-sheet.busy .ai-card { opacity: .5; pointer-events: none; }

.ai-form { padding: 10px 14px 12px; }
.ai-box {
  display: flex; align-items: flex-end; gap: 8px; padding: 6px 6px 6px 14px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 22px; transition: border-color .15s, box-shadow .15s;
}
.ai-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ai-box textarea {
  flex: 1; min-width: 0; resize: none; border: 0; outline: none; background: none; color: var(--fg);
  font: inherit; font-size: 14px; line-height: 22px; padding: 5px 0; max-height: 120px; box-shadow: none;
}
.ai-box textarea:focus { box-shadow: none; }
.ai-send {
  flex: 0 0 34px; width: 34px; height: 34px; padding: 0; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-grad); border-color: transparent; color: #fff; box-shadow: var(--shadow-btn);
}
.ai-send:hover { color: #fff; filter: brightness(1.06); }
.ai-foot { color: var(--fg-dim); font-size: 11px; text-align: center; margin-top: 6px; }

@media (max-width: 860px) {
  #ai-sheet {
    position: fixed; left: 0; right: 0; bottom: 0; height: 52%; border-radius: var(--r-pop) var(--r-pop) 0 0;
    background: var(--glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); box-shadow: var(--shadow-pop);
    border-left: 0; border-right: 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom);
    animation-name: ai-up;
  }
  @keyframes ai-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
  .ai-sub, .ai-foot { display: none; }
  .ai-head { padding: 8px 10px; }
  .ai-badge { flex-basis: 28px; height: 28px; font-size: 11px; border-radius: 8px; }
  .ai-log { padding: 10px; gap: 10px; }
  .ai-hello { font-size: 17px; }
  .ai-hello-sub { font-size: 12.5px; margin-bottom: 10px; }
  .ai-cards { gap: 8px; }
  .ai-card { padding: 9px; grid-template-columns: 28px 1fr; column-gap: 8px; }
  .ai-card .ai-ic { width: 28px; height: 28px; border-radius: 8px; }
  .ai-form { padding: 8px 10px 10px; }
  .ai-box textarea { font-size: 16px; }   /* 16px 以下 iOS 聚焦会自动放大页面 */
}
/* 手机顶栏放不下：装配模式里「退出装配」较长，「问AI」缩成「AI」、去掉分隔线 */
@media (max-width: 620px) {
  #btn-ai .wide-only, #toolbar .sep { display: none; }
}
/* 空的读数框 / 装配模式下宽屏左栏空表头不占位 */
#hud:empty { display: none; }
@media (min-width: 861px) { #app.asm-mode #left .panel-head { display: none; } }
@media (max-width: 620px) {
  /* 外框留白后顶栏又窄了 12px：按钮内边距再收一点，装配模式一排仍放得下 */
  #topbar { padding: 0 4px; gap: 4px; }
  #toolbar { gap: 3px; }
  #topbar button, #toolbar .tool, #toolbar button { padding-left: 6px; padding-right: 6px; }
}

/* ---------- 单独查看：只留一步、正对装配面 ---------- */
.asm-solo-bar {
  position: absolute; z-index: 12; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 14px; max-width: calc(100% - 20px);
  background: var(--glass); border: 1px solid #fff; border-radius: var(--r-pop); box-shadow: var(--shadow-pop);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); white-space: nowrap;
}
.asm-solo-bar[hidden] { display: none; }
.asm-solo-t { font-size: 13px; color: var(--fg-dim); overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.asm-solo-t b { color: var(--fg); margin: 0 4px; font-size: 14px; }
.asm-solo-t small { font-size: 12px; }
.asm-seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-btn); }
.asm-seg button { border: 0; background: none; padding: 5px 11px; border-radius: 8px; box-shadow: none; }
.asm-seg button.active { background: var(--accent-grad); color: #fff; box-shadow: var(--shadow-btn); }
.asm-solo-x { padding: 6px 12px; }
/* 单独查看时底部步骤条让位（翻步会自动退出单独查看，避免误触） */
#app.asm-solo #asm-bar { display: none !important; }
.asm-acts { grid-column: 4; grid-row: 1 / 3; align-self: center; display: flex; gap: 4px; }
.asm-acts .asm-enter { grid-column: auto; grid-row: auto; }
.asm-solo-btn { display: none; min-height: 30px; padding: 0 10px; font-size: 13px; }
.asm-step.cur .asm-solo-btn { display: inline-block; }
.asm-solo-go { width: 100%; margin-bottom: 8px; min-height: 36px; font-weight: 600; color: var(--accent); border-color: #2f6bff55; background: var(--accent-soft); }
@media (max-width: 620px) {
  .asm-solo-bar { top: 8px; left: 6px; right: 6px; transform: none; max-width: none; gap: 6px; padding: 5px 5px 5px 10px; }
  .asm-solo-t small { display: none; }
  .asm-seg button { padding: 5px 8px; }
  .asm-solo-x { padding: 6px 9px; }
}
.asm-solo-t i { font-style: normal; }
@media (max-width: 620px) {
  .asm-solo-t i { display: none; }          /* 手机：只留组立名，别被截成「DK2…」 */
  .asm-solo-t b { margin-left: 0; }
  .asm-solo-t { flex: 1 1 auto; }
}
