/* ============================================================
   模卡模板设计器 · 样式表
   布局：CSS Grid 三栏（模板库 / 画布 / 属性）
   ============================================================ */

/* ---------- 可选中文字体（免费可商用） ----------
   字体文件在 editor/fonts/，已按「ASCII + GB2312 一级汉字」子集化成 woff2
   （每个约 490KB，比原始 8MB 小 94%）。子集脚本见 tools/gen_fonts.py。
   注意：canvas 测量字宽前必须等字体加载完，见 render.js 的 ensureFontsLoaded()。 */
@font-face {
  font-family: 'MokaHarmony';
  src: url('fonts/HarmonyOS-Sans-SC-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: block;
}
@font-face {
  font-family: 'MokaHarmony';
  src: url('fonts/HarmonyOS-Sans-SC-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: block;
}
@font-face {
  font-family: 'MokaAlibaba';
  src: url('fonts/Alibaba-PuHuiTi-3-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: block;
}
@font-face {
  font-family: 'MokaAlibaba';
  src: url('fonts/Alibaba-PuHuiTi-3-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: block;
}

* { box-sizing: border-box; }

:root {
  --bg-0: #0e1116;
  --bg-1: #161b22;
  --bg-2: #1c2230;
  --bg-3: #232b3a;
  --bg-4: #2c3648;
  --line: #2a3342;
  --line-2: #384456;
  --txt-0: #e6ecf5;
  --txt-1: #b3bfd0;
  --txt-2: #7d8a9e;
  --accent: #4c8dff;
  --accent-2: #2f6fe0;
  --ok: #3ecf8e;
  --warn: #f0a93b;
  --danger: #ef5b6a;
  --sel: #4c8dff;
  --radius: 7px;
  --radius-sm: 5px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  --font: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Mono", "Consolas", "SF Mono", monospace;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--txt-0);
  font: 13px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
input, select, textarea { outline: none; }

/* ── 滚动条 ── */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--line-2); background-clip: padding-box; }

/* ============================================================
   总布局
   ============================================================ */
#app {
  display: grid;
  grid-template-columns: 266px minmax(0, 1fr) 328px;
  grid-template-rows: 52px minmax(0, 1fr);
  grid-template-areas:
    "top   top   top"
    "left  main  right";
  height: 100vh;
  width: 100vw;
}

/* ============================================================
   顶栏
   ============================================================ */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  background: linear-gradient(180deg, #1a2130, #141922);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}

.brand { display: flex; align-items: baseline; gap: 8px; flex: none; }
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: linear-gradient(135deg, #4c8dff, #8f6bff);
  box-shadow: 0 0 10px rgba(76, 141, 255, .7);
  align-self: center;
}
.brand-name { font-size: 14.5px; font-weight: 600; letter-spacing: .3px; }
.brand-sub { font-size: 10.5px; color: var(--txt-2); letter-spacing: .4px; text-transform: uppercase; }

.doc-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}
.doc-name {
  width: 190px;
  height: 28px;
  padding: 0 9px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-weight: 500;
  min-width: 0;
  flex: 0 1 auto;
}
.doc-name:focus { border-color: var(--accent); background: var(--bg-2); }
.doc-key {
  font: 11px/1 var(--mono);
  color: var(--txt-2);
  padding: 5px 7px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
}
.size-field {
  display: flex; align-items: center; gap: 4px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 7px;
  height: 28px;
  flex: none;
}
.size-field > span { font: 10.5px/1 var(--mono); color: var(--txt-2); }
.size-field > input {
  width: 52px; border: 0; background: transparent;
  height: 100%; padding: 0;
  font: 12px/1 var(--mono);
}

/* 后端地址：比 W/H 长得多，但又不能抢掉 .doc-meta 里名称的位置，
   所以给固定宽度 + 省略号，超长时靠 title 看全 */
.api-field > input {
  width: 150px;
  font-size: 11px;
  text-overflow: ellipsis;
  color: var(--txt-1);
}
.api-field > input:focus { color: var(--txt-0); }

/* 连接状态灯：默认黄色（未连接），连上后转绿。
   用 cursor:pointer + 点击重连，避免为了确认后端状态反复刷页面 */
.api-state {
  display: inline-flex; align-items: center;
  height: 28px; padding: 0 8px;
  font: 11px/1 var(--mono);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  flex: none;
}
.api-state.warn { color: var(--warn); border-color: rgba(240, 169, 59, .35); background: rgba(240, 169, 59, .08); }
.api-state.ok { color: var(--ok); border-color: rgba(62, 207, 142, .35); background: rgba(62, 207, 142, .08); }
.api-state:hover { border-color: currentColor; }

.top-actions { display: flex; align-items: center; gap: 6px; flex: none; }

/* ============================================================
   通用控件
   ============================================================ */
.btn {
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--txt-1);
  font-size: 12px;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--bg-3); color: var(--txt-0); border-color: #44506a; }
.btn:active { background: var(--bg-4); transform: translateY(.5px); }
.btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-color: var(--accent-2);
  color: #fff;
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger:hover { background: #4a2028; border-color: var(--danger); color: #ffb3ba; }
.btn.icon { padding: 0; width: 28px; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; }
.btn.xs { height: 23px; padding: 0 8px; font-size: 11.5px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .38; pointer-events: none; }
.btn.on { background: var(--accent-2); border-color: var(--accent); color: #fff; }

/* 顶栏按钮三层权重，解决「9 个按钮长得一样、找不到重点」：
   primary 实心 = 唯一的主操作（保存模板）
   outline 描边 = 不可撤销的强调动作（发布）
   ghost 透明   = 次要动作（适应窗口 / 导入导出），悬停才浮现边框 */
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--txt-2);
}
.btn.ghost:hover {
  background: var(--bg-2);
  border-color: var(--line-2);
  color: var(--txt-0);
}
.btn.outline {
  background: rgba(76, 141, 255, .10);
  border-color: rgba(76, 141, 255, .45);
  color: #9cc0ff;
}
.btn.outline:hover {
  background: rgba(76, 141, 255, .18);
  border-color: rgba(76, 141, 255, .72);
}

.sep { width: 1px; height: 18px; background: var(--line); flex: none; }
.spacer { flex: 1 1 auto; }

.chk {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--txt-1); cursor: pointer; white-space: nowrap;
}
.chk input { accent-color: var(--accent); margin: 0; width: 13px; height: 13px; }

.mini-select {
  height: 26px;
  padding: 0 5px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12px;
}
.mini-select:focus { border-color: var(--accent); }
.mini-select.block, .mini-select.grow { flex: 1 1 auto; width: 100%; }

.mini-num {
  width: 66px; height: 25px; padding: 0 6px;
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: 12px/1 var(--mono);
}

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  height: 18px; background: transparent; flex: 1 1 auto; min-width: 40px;
  accent-color: var(--accent);
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: var(--bg-4);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0d1117;
  margin-top: -4px;
  box-shadow: 0 0 0 1px var(--accent-2);
}
.range-val { font: 11px/1 var(--mono); color: var(--txt-2); min-width: 34px; text-align: right; }

/* ============================================================
   左侧模板库
   ============================================================ */
.sidebar-left {
  grid-area: left;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-1);
  border-right: 1px solid var(--line);
}
.panel-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px 8px;
  flex: none;
}
.panel-title { font-size: 12.5px; font-weight: 600; color: var(--txt-0); letter-spacing: .2px; }
.panel-badge {
  margin-left: auto;
  font: 10.5px/1 var(--mono);
  padding: 3px 6px;
  border-radius: 20px;
  background: var(--bg-3);
  color: var(--txt-2);
}

.lib-search { padding: 0 12px 8px; flex: none; }
.lib-search input {
  width: 100%; height: 29px; padding: 0 9px;
  background: var(--bg-0);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12px;
}
.lib-search input:focus { border-color: var(--accent); }

.group-tabs {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 0 12px 9px;
  flex: none;
  border-bottom: 1px solid var(--line);
}
.gtab {
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--bg-2);
  border: 1px solid transparent;
  color: var(--txt-2);
  font-size: 11.5px;
}
.gtab:hover { color: var(--txt-0); background: var(--bg-3); }
.gtab.active {
  background: rgba(76, 141, 255, .16);
  border-color: rgba(76, 141, 255, .5);
  color: #9cc0ff;
}

/* 单列而不是两列：侧栏 266px 切成两列后每张卡只有 119px、缩略图 117×56，
   而模卡是 1500×800 的多图版式 —— 那个尺寸下缩略图退化成一条颜色带，
   等于无法靠看图辨认，只能读名字，而名字 11px 在 119px 里 8 个字就省略号。
   改单列后缩略图 246×119（可视面积 ×4.3），一眼能分出「5竖图 / 环绕 / 底部」。
   56 项变长的问题交给分组 tab + 搜索解决，比"一屏塞更多但都看不清"划算。 */
.lib-list {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 9px 10px 6px;
  display: grid;
  grid-template-columns: 1fr;
  /* 必须显式 max-content：缩略图是 `width:100% + aspect-ratio`，隐式 auto 行
     在算 min-content 高度时拿不到确定宽度，会把整张卡片算成 0 高（只剩 1px 边框），
     内容 166px 被 .lib-card 的 overflow:hidden 裁成一条横线。
     max-content 让行高按内容的实际高度取，实测 166px 恢复完整卡片。 */
  grid-auto-rows: max-content;
  gap: 9px;
  align-content: start;
}

.lib-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .12s, transform .12s;
}
.lib-card:hover { border-color: var(--line-2); transform: translateY(-1px); }
.lib-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(76, 141, 255, .45); }
.lib-card.disabled { opacity: .55; }
.lib-card-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 330 / 160;
  background: #0a0d12 center/cover no-repeat;
  object-fit: cover;
}
.lib-card-thumb.blank {
  display: flex; align-items: center; justify-content: center;
  font: 10.5px/1 var(--mono); color: var(--txt-2);
}
.lib-card-meta {
  padding: 6px 9px 7px;
  display: flex; flex-direction: column; gap: 3px;
}
.lib-card-name {
  font-size: 12.5px; color: var(--txt-1);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* 服务器来源角标：卡片名是 nowrap+ellipsis，在里面塞 inline 元素不会撑破，
   但要让省略号在角标之后才出现，所以用 inline-flex + 溢出裁到名字那层 */
.srv {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 3px;
  border-radius: 3px;
  font: 9px/1 var(--mono);
  font-style: normal;
  color: var(--accent);
  border: 1px solid rgba(76, 141, 255, .5);
  background: rgba(76, 141, 255, .12);
  vertical-align: 1px;
}
.lib-card-key {
  font: 10px/1.2 var(--mono);
  color: var(--txt-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lib-card-tag {
  position: absolute; top: 4px; right: 4px;
  font: 9px/1 var(--mono);
  padding: 3px 4px;
  border-radius: 3px;
  background: rgba(0, 0, 0, .66);
  color: #cfd8e6;
  backdrop-filter: blur(2px);
}
/* 服务器模板的删除按钮：悬停浮现，右上角（tag 左侧） */
.lib-card-del {
  position: absolute; top: 4px; right: 34px;
  width: 18px; height: 18px;
  padding: 0;
  font: 11px/1 var(--mono);
  border-radius: 3px;
  border: 1px solid rgba(239, 91, 106, .5);
  background: rgba(0, 0, 0, .66);
  color: #ff9aa4;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s, background .12s;
  backdrop-filter: blur(2px);
}
.lib-card:hover .lib-card-del { opacity: 1; }
.lib-card-del:hover { background: var(--danger); color: #fff; }

/* ══════════ 模板库「商品化管理」 ══════════
   状态徽标 / 勾选框 / 单卡快捷操作 / 批量工具条。
   为什么要有：只有 published 会下发到小程序，草稿与已下架在小程序里都看不见，
   状态不摆在卡片上，运营就会一直问"我保存了怎么小程序没有"。 */
.lib-card-check {
  position: absolute; top: 5px; left: 5px;
  width: 15px; height: 15px; margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
  z-index: 3;
  /* 常显一档而不是 opacity:0 —— 原来必须把鼠标移到卡片上才浮现，
     等于「怎么多选/怎么做批量操作」没有任何视觉入口。
     0.32 在深色缩略图上刚好能看见又不抢戏，悬停和已勾选时拉满。 */
  opacity: .32;
  transition: opacity .12s;
}
.lib-card:hover .lib-card-check,
.lib-card.is-checked .lib-card-check { opacity: 1; }
.lib-card.is-checked { outline: 2px solid var(--accent); outline-offset: -1px; }
.lib-card.is-offline .lib-card-thumb { filter: grayscale(.7) brightness(.75); }

/* 状态徽标：左下角，与右上角的「N图」区分开 */
.lib-status {
  position: absolute; left: 4px; bottom: 38px;
  font: 9px/1 var(--mono);
  padding: 3px 5px;
  border-radius: 3px;
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.lib-status.st-published { background: rgba(62, 207, 142, .22); color: #7ef0bb; border: 1px solid rgba(62, 207, 142, .45); }
.lib-status.st-draft     { background: rgba(240, 169, 59, .20); color: #f5c071; border: 1px solid rgba(240, 169, 59, .42); }
.lib-status.st-offline   { background: rgba(150, 160, 175, .20); color: #b9c2d0; border: 1px solid rgba(150, 160, 175, .40); }

/* 单卡快捷操作：悬停浮现在缩略图底部 */
.lib-card-acts {
  position: absolute; left: 4px; right: 4px; bottom: 30px;
  display: flex; gap: 3px;
  opacity: 0;
  transition: opacity .12s;
}
.lib-card:hover .lib-card-acts { opacity: 1; }
.lib-act {
  flex: 1;
  padding: 2px 0;
  font: 10px/1.4 var(--mono);
  border-radius: 3px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .72);
  color: #cfd8e6;
  cursor: pointer;
  backdrop-filter: blur(2px);
}
.lib-act:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.lib-act.danger { border-color: rgba(239, 91, 106, .5); color: #ff9aa4; }
.lib-act.danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

/* 批量工具条 */
.lib-batch {
  margin: 0 10px 8px;
  padding: 8px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: rgba(76, 141, 255, .08);
  display: flex; flex-direction: column; gap: 6px;
}
.lib-batch[hidden] { display: none; }
.lib-batch-row { display: flex; align-items: center; gap: 6px; }
.lib-batch-row .btn { flex: 1; }
.lib-batch-row .mini-select { flex: 1.4; min-width: 0; }
.lib-batch-count {
  flex: 1;
  font: 11px/1 var(--mono);
  color: var(--accent);
}

/* 模板封面预览（样式主题 tab 底部） */
.cover-preview {
  margin: 6px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-0);
}
.cover-preview img {
  display: block;
  width: 100%;
  aspect-ratio: 330 / 190;
  object-fit: cover;
  background: #0a0d12;
}
.cover-preview-name {
  padding: 4px 6px;
  font: 9.5px/1.3 var(--mono);
  color: var(--txt-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lib-empty {
  grid-column: 1 / -1;
  padding: 26px 10px;
  text-align: center;
  color: var(--txt-2);
  font-size: 12px;
  /* 搜索空态里会多出「其它分组命中 N 个」和一键跳转按钮 */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}
.lib-empty-sub {
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--txt-2);
  opacity: .85;
}

.lib-foot { padding: 8px 10px 10px; flex: none; border-top: 1px solid var(--line); }

/* ============================================================
   中间舞台
   ============================================================ */
.stage-wrap {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-0);
}

.stage-toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 10px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  flex: none;
  /* 原来是 nowrap + overflow-x:auto：内容 1038px 而 1440 屏只有 846px 可用，
     于是置顶/置底/缩放四个按钮被裁到滚动区外 —— 不横向滚就不知道有这些功能。
     收掉 4 个插入按钮（改下拉）后再允许换行兜底：更窄的屏最多折成两行，
     不会有控件被藏起来。 */
  flex-wrap: wrap;
  row-gap: 6px;
}
.stage-toolbar .btn.icon { width: 26px; }
.tool-group { display: flex; align-items: center; gap: 4px; flex: none; }
/* 工具栏内的控件比默认再紧一档：吸附/网格线/标尺三个 checkbox 与网格下拉
   合计占了近 200px，是超出可用宽度的大头之一 */
.stage-toolbar .chk { gap: 4px; font-size: 11.5px; }
.stage-toolbar .chk input { width: 12px; height: 12px; }
.stage-toolbar .mini-select { font-size: 11.5px; height: 25px; }
.zoom-group { display: flex; align-items: center; gap: 4px; flex: none; }
.zoom-val {
  font: 11px/1 var(--mono);
  color: var(--txt-1);
  min-width: 34px;
  text-align: center;
}

/* 工具栏里的下拉（目前用于「插入元素」） */
.dropdown { position: relative; display: flex; flex: none; }
.dropdown-toggle { width: auto !important; padding: 0 6px; }
.dropdown-toggle .caret { font-size: 9px; opacity: .75; margin-left: 2px; }
.dropdown-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 134px;
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .55);
  z-index: 45;
}
.dropdown-panel[hidden] { display: none; }
.dropdown-panel .btn {
  display: inline-flex; align-items: center; justify-content: flex-start;
  width: 100%; height: 26px; padding: 0 8px; font-size: 12px;
}
.dp-label {
  font-size: 10.5px; color: var(--txt-2);
  padding: 2px 4px 1px; letter-spacing: .3px;
}
.dp-select { width: 100%; }
.dropdown-panel .chk { padding: 3px 4px; font-size: 12px; }

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  /* display:grid 只为一件事：让 #canvasWrap 的 margin:auto 在纵向也生效。
     原来是普通 block 容器，auto margin 只在水平方向起作用，画布永远贴顶
     （上留 90px、下留 300px，看着像没对齐）。
     用 grid + auto margin 而不是居中对齐属性：grid item 的 auto margin 在
     内容超出容器时会自动归零、从起点开始排布 —— 所以放大到 200% 仍能滚到
     顶部，避开了 flex/grid 居中「顶部滚不到」的经典坑。 */
  display: grid;
  background:
    radial-gradient(circle at 50% 40%, #151b26 0%, #0b0e13 70%),
    var(--bg-0);
  padding: 34px 40px 40px 44px;
}
.stage.no-ruler { padding: 22px 24px; }

#canvasWrap {
  position: relative;
  margin: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .55), 0 0 0 1px rgba(255, 255, 255, .06);
  background: #fff;
  transition: box-shadow .12s;
}
#canvasWrap.dragover { box-shadow: 0 0 0 2px var(--accent), 0 10px 40px rgba(0, 0, 0, .55); }

#canvas {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  overflow: hidden;
  background: #000;
}

.grid-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, .10) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, .10) 1px, transparent 1px);
  background-size: 50px 50px;
}
.grid-overlay.show { display: block; }

.slots { position: absolute; inset: 0; }

/* ── 槽位 ── */
.slot {
  position: absolute;
  overflow: hidden;
  outline: 1px solid rgba(255, 255, 255, .22);
  outline-offset: -1px;
  cursor: move;
}
.slot > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}
.slot.photo.empty {
  background:
    repeating-linear-gradient(45deg, #1a1f2a 0 8px, #232a37 8px 16px);
}
.slot.photo.empty::after {
  content: attr(data-label);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 10px/1 var(--mono);
  color: rgba(255, 255, 255, .5);
  letter-spacing: .5px;
}
/* ── logo / 小程序码占位区 ─────────────────────────────── */
.slot.deco-logo {
  background:
    repeating-linear-gradient(45deg, #14202e 0 8px, #1a2a3a 8px 16px);
  border: 1px dashed rgba(76, 141, 255, .45);
}
.slot.deco-code {
  background:
    radial-gradient(circle at 25% 25%, rgba(255,255,255,.28) 0 12%, transparent 13%),
    radial-gradient(circle at 75% 25%, rgba(255,255,255,.28) 0 12%, transparent 13%),
    radial-gradient(circle at 25% 75%, rgba(255,255,255,.28) 0 12%, transparent 13%),
    repeating-linear-gradient(45deg, #10161f 0 6px, #182030 6px 12px);
  border: 1px dashed rgba(255, 255, 255, .35);
}
.deco-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 600 10px/1 var(--mono);
  color: rgba(255, 255, 255, .55);
  letter-spacing: 1px;
  pointer-events: none;
}
.slot.deco-code .deco-label { font-size: 9px; }
/* logo 槽带真实图（或本地待上传 data URL）时：img 铺满、label 变角标浮在上层 */
.slot.deco-hasimg > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
/* logo 预览（属性面板里） */
.logo-preview {
  margin-top: 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  overflow: hidden;
  background: var(--bg-0);
}
.logo-preview img {
  display: block;
  width: 100%;
  height: 74px;
  object-fit: contain;
  background: repeating-conic-gradient(#222a36 0 25%, #1a212c 0 50%) 0 0 / 12px 12px;
}
.logo-preview-name {
  display: block;
  font: 10px/1.5 var(--mono);
  color: var(--txt-2);
  padding: 3px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slot:hover { outline-color: rgba(76, 141, 255, .8); }
.slot.selected {
  outline: 2px solid var(--sel);
  outline-offset: -2px;
  z-index: 5;
}

/* 缩放手柄 */
.handle {
  position: absolute;
  width: 11px; height: 11px;
  background: #fff;
  border: 2px solid var(--sel);
  border-radius: 2px;
  z-index: 8;
  display: none;
}
.slot.selected .handle { display: block; }
.handle[data-h="nw"] { left: -6px;  top: -6px;    cursor: nwse-resize; }
.handle[data-h="n"]  { left: 50%;   top: -6px;    margin-left: -5.5px; cursor: ns-resize; }
.handle[data-h="ne"] { right: -6px; top: -6px;    cursor: nesw-resize; }
.handle[data-h="e"]  { right: -6px; top: 50%;     margin-top: -5.5px; cursor: ew-resize; }
.handle[data-h="se"] { right: -6px; bottom: -6px; cursor: nwse-resize; }
.handle[data-h="s"]  { left: 50%;   bottom: -6px; margin-left: -5.5px; cursor: ns-resize; }
.handle[data-h="sw"] { left: -6px;  bottom: -6px; cursor: nesw-resize; }
.handle[data-h="w"]  { left: -6px;  top: 50%;     margin-top: -5.5px; cursor: ew-resize; }

/* 尺寸标签 */
.slot-size {
  position: absolute;
  left: 50%;
  bottom: 3px;
  transform: translateX(-50%);
  padding: 2px 5px;
  border-radius: 3px;
  background: rgba(0, 0, 0, .72);
  color: #dfe8f5;
  font: 9.5px/1 var(--mono);
  white-space: nowrap;
  pointer-events: none;
  display: none;
}
.slot.selected .slot-size { display: block; }

/* 索引角标 */
.slot-idx {
  position: absolute;
  left: 3px; top: 3px;
  min-width: 15px;
  padding: 2px 3px;
  border-radius: 3px;
  background: rgba(0, 0, 0, .6);
  color: #dbe4f0;
  font: 9.5px/1 var(--mono);
  text-align: center;
  pointer-events: none;
}
.slot.info .slot-idx { background: rgba(76, 141, 255, .8); color: #fff; }
.slot.deco-logo .slot-idx { background: rgba(76, 141, 255, .55); color: #fff; }
.slot.deco-code .slot-idx { background: rgba(62, 207, 142, .6); color: #fff; }

/* ── 资料槽渲染容器 ── */
.info-render {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  color: #fff;
}
.info-render .ir-box { position: absolute; }

/* ── 智能参考线 ── */
.guides { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
.guide {
  position: absolute;
  background: #ff4d8d;
  box-shadow: 0 0 4px rgba(255, 77, 141, .9);
}
.guide.v { width: 1px; top: 0; bottom: 0; }
.guide.h { height: 1px; left: 0; right: 0; }

/* ── 标尺 ── */
.ruler-h, .ruler-v {
  position: absolute;
  background: var(--bg-1);
  border-color: var(--line);
  z-index: 12;
  overflow: hidden;
  pointer-events: none;
  display: none;
}
.ruler-h { left: 0; right: 0; top: 0; height: 20px; border-bottom: 1px solid var(--line); }
.ruler-v { top: 0; bottom: 0; left: 0; width: 20px; border-right: 1px solid var(--line); }
.stage.show-ruler .ruler-h, .stage.show-ruler .ruler-v { display: block; }
.ruler-tick { position: absolute; background: var(--line-2); }
.ruler-h .ruler-tick { width: 1px; }
.ruler-h .ruler-tick.major { height: 7px; bottom: 0; background: #55637c; }
.ruler-h .ruler-tick.minor { height: 3px; bottom: 0; }
.ruler-v .ruler-tick { height: 1px; }
.ruler-v .ruler-tick.major { width: 7px; right: 0; background: #55637c; }
.ruler-v .ruler-tick.minor { width: 3px; right: 0; }
.ruler-label {
  position: absolute;
  font: 9px/1 var(--mono);
  color: var(--txt-2);
  white-space: nowrap;
}
.ruler-h .ruler-label { top: 2px; transform: translateX(2px); }
.ruler-v .ruler-label {
  left: 1px; transform: rotate(-90deg); transform-origin: 0 0;
}

/* ── 状态栏 ── */
.statusbar {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 27px;
  padding: 0 12px;
  background: var(--bg-1);
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--txt-2);
  flex: none;
}
#statusStats { font-family: var(--mono); font-size: 10.5px; }
.issues {
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 11px;
}
.issues.ok { background: rgba(62, 207, 142, .14); color: var(--ok); }
.issues.warn { background: rgba(240, 169, 59, .16); color: var(--warn); }
.issues.err { background: rgba(239, 91, 106, .16); color: var(--danger); }

/* ============================================================
   右侧属性面板
   ============================================================ */
.sidebar-right {
  grid-area: right;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-1);
  border-left: 1px solid var(--line);
}
.inspector { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }

.ins-tabs {
  display: flex;
  flex: none;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.ins-tab {
  flex: 1 1 0;
  height: 35px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--txt-2);
  font-size: 12px;
  transition: color .12s, border-color .12s;
}
.ins-tab:hover { color: var(--txt-0); }
.ins-tab.active { color: #9cc0ff; border-bottom-color: var(--accent); background: var(--bg-1); }

.ins-body {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  padding: 2px 0 20px;
}
.ins-body[hidden] { display: none; }

.ins-section { padding: 11px 13px; border-bottom: 1px solid var(--line); }
.ins-section:last-child { border-bottom: 0; }
.ins-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--txt-1);
  letter-spacing: .5px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.ins-section-title.tiny { text-transform: none; letter-spacing: 0; font-size: 11px; color: var(--txt-2); margin-top: 4px; }

/* 小节标题 + 右侧操作按钮（「资料字段 + 加字段」这种） */
.ins-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.ins-section-head .ins-section-title { margin-bottom: 0; }

/* 全宽文本输入（昵称） */
.text-input {
  width: 100%;
  padding: 6px 8px;
  font: 12.5px/1.3 var(--font);
  color: var(--txt-0);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  outline: none;
}
.text-input:focus { border-color: var(--accent); }

/* ---------- 资料字段列表 ----------
   每张卡两行：① 开关 中文名 英文名 缩写 行号 ↑ ↓ ×  ② 值 单位
   328px 属性栏里要放得下，所以输入框都很窄、用等宽小字号。 */
.field-list { display: flex; flex-direction: column; gap: 6px; }

.fld {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) minmax(0, 1fr) 44px 42px auto;
  grid-template-areas:
    "eye label en  abbr row acts"
    "eye value value unit row acts";
  gap: 4px 5px;
  align-items: center;
  padding: 6px 7px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.fld:hover { border-color: var(--bg-4); }
.fld.off { opacity: .5; }

.fld-eye {
  grid-area: eye;
  width: 16px; height: 16px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--txt-3);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.fld-eye.on { color: var(--ok); }
.fld-label { grid-area: label; }
.fld-en    { grid-area: en; }
.fld-abbr  { grid-area: abbr; }
.fld-value { grid-area: value; }
.fld-unit  { grid-area: unit; }

.fld-row {
  grid-area: row;
  width: 100%;
  padding: 3px 2px;
  font: 11px/1 var(--mono);
  color: var(--txt-1);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
  max-width: 42px;
}

.fld-acts {
  grid-area: acts;
  display: flex;
  gap: 2px;
}
.fld-acts > button {
  width: 17px; height: 17px;
  padding: 0;
  font: 11px/1 var(--font);
  color: var(--txt-2);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 3px;
  cursor: pointer;
}
.fld-acts > button:hover { color: var(--txt-0); border-color: var(--bg-4); }
.fld-acts > button.del:hover { color: #fff; background: var(--danger); border-color: var(--danger); }

.fld input[type="text"] {
  min-width: 0;
  width: 100%;
  padding: 4px 5px;
  font: 11.5px/1.2 var(--font);
  color: var(--txt-0);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  outline: none;
}
.fld input[type="text"]:focus { border-color: var(--accent); }
.fld input[type="text"]::placeholder { color: var(--txt-3); }

.ins-note {
  margin: 7px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--txt-2);
}
.ins-note.dim { opacity: .72; margin-top: 4px; }

.empty-hint {
  padding: 40px 20px;
  text-align: center;
  color: var(--txt-2);
  font-size: 12px;
  line-height: 1.7;
}

/* 未选中槽位时的模板概览（替代原来那 800px 空白） */
.ins-overview { padding: 14px 14px 18px; }
.ov-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 9px;
}
.ov-title {
  font-size: 10.5px; color: var(--txt-2);
  letter-spacing: .6px; text-transform: uppercase;
}
.ov-renderer {
  font: 10px/1 var(--mono);
  padding: 3px 6px; border-radius: 3px;
  background: var(--bg-3); color: var(--txt-1);
}
.ov-name {
  font-size: 15px; font-weight: 600; line-height: 1.35;
  color: var(--txt-0); margin-bottom: 3px;
  word-break: break-all;
}
.ov-key {
  font: 10.5px/1.3 var(--mono); color: var(--txt-2);
  margin-bottom: 13px; word-break: break-all;
}
.ov-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.ov-cell {
  display: flex; flex-direction: column; gap: 3px;
  padding: 7px 9px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.ov-k { font-size: 10.5px; color: var(--txt-2); }
.ov-v { font: 13px/1.2 var(--mono); color: var(--txt-0); }
.ov-hint {
  margin-top: 15px; padding-top: 13px;
  border-top: 1px solid var(--line);
  font-size: 11.5px; line-height: 1.75; color: var(--txt-2);
}

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.field-grid.one { grid-template-columns: 1fr; gap: 6px; }
.field-grid > label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--txt-2);
}
.field-grid > label > input {
  flex: 1 1 auto;
  min-width: 0;
  height: 25px;
  padding: 0 6px;
  background: var(--bg-0);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--txt-0);
  font: 12px/1 var(--mono);
}
.field-grid > label > input[type="text"] { font: 12px/1 var(--font); }
.field-grid > label > input:focus { border-color: var(--accent); }
.field-grid.one > label { justify-content: space-between; }
.field-grid.one > label > input { flex: 0 1 62%; }

.field-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 7px;
}
.field-row:first-child { margin-top: 0; }
.mini-label { font-size: 11.5px; color: var(--txt-2); flex: none; min-width: 34px; }

/* 资料字段 chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--txt-2);
  font-size: 11.5px;
}
.chip:hover { background: var(--bg-3); color: var(--txt-0); }
.chip.on {
  background: rgba(76, 141, 255, .16);
  border-color: rgba(76, 141, 255, .55);
  color: #9cc0ff;
}

/* 图片池 */
.photo-pool {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  max-height: 232px;
  overflow-y: auto;
  padding: 2px;
  margin-top: 6px;
}
.pool-item {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-0) center/cover no-repeat;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: border-color .12s, transform .12s;
}
.pool-item:hover { border-color: var(--accent); transform: scale(1.04); }
.pool-item.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.pool-group-title {
  grid-column: 1 / -1;
  font: 10px/1 var(--mono);
  color: var(--txt-2);
  padding: 5px 1px 1px;
  letter-spacing: .3px;
}

/* 预设 */
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.preset {
  position: relative;
  height: 52px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .12s;
}
.preset:hover { border-color: var(--line-2); }
.preset.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.preset-label {
  position: absolute;
  left: 5px; bottom: 3px;
  font: 9.5px/1 var(--mono);
  padding: 2px 4px;
  border-radius: 3px;
  background: rgba(0, 0, 0, .5);
}
.preset-swatch {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
  font-size: 11.5px;
  color: var(--txt-2);
}
.color-row > span { flex: 0 0 48px; }
.color-row input[type="color"] {
  width: 26px; height: 25px;
  padding: 0; border: 1px solid var(--line);
  border-radius: 4px; background: transparent;
  cursor: pointer;
  flex: none;
}
.color-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.color-row input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 2px; }
.hex-input {
  width: 84px; height: 25px; padding: 0 6px;
  background: var(--bg-0);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: 11.5px/1 var(--mono);
  text-transform: uppercase;
}
.hex-input:focus { border-color: var(--accent); }

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 54px;
  transform: translate(-50%, 16px);
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(28, 34, 48, .96);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow);
  color: var(--txt-0);
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 200;
  max-width: 70vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--danger); color: #ffb8c0; }
.toast.ok { border-color: var(--ok); color: #a6f0ce; }

/* ============================================================
   弹窗
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 14, .72);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
}
.modal[hidden] { display: none; }
.modal-box {
  width: min(760px, 88vw);
  height: min(620px, 82vh);
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: 11px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ── 分类管理弹窗（= 分组 CRUD）────────────────────────────── */
.cat-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}
.cat-row:last-child { border-bottom: 0; }
.cat-name {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--fg);
  padding: 6px 8px;
  font-size: 12.5px;
}
.cat-name:focus { outline: none; border-color: var(--accent); }
.cat-renderer { flex: none; width: 168px; }
.cat-count { flex: none; color: var(--fg-3); font-size: 11.5px; white-space: nowrap; }
.cat-del { flex: none; }
.cat-del:hover { color: var(--danger); border-color: var(--danger); }
.lib-foot .btn + .btn { margin-top: 6px; }
.modal-head {
  display: flex;
  align-items: center;
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  flex: none;
}
.modal-head > span { flex: 1 1 auto; }
#modalText {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  resize: none;
  background: var(--bg-0);
  color: #b9d3ff;
  font: 11.5px/1.6 var(--mono);
  user-select: text;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 13px;
  border-top: 1px solid var(--line);
  flex: none;
}

/* ============================================================
   窄屏适配
   ============================================================ */
/* 顶栏是单行 flex，放不下就只会挤名称输入框（.doc-name 是唯一可压的），
   实测 1440 宽时 #apiBase 会把 doc-name 从 190 压到 78px，名字几乎看不见。
   所以中等宽度直接收起地址框——地址存在 localStorage 里不会丢，
   需要改时双击状态灯即可（见 editor.js 的 apiState dblclick）。 */
@media (max-width: 1500px) {
  .api-field { display: none; }
  .doc-name { min-width: 140px; }
}
@media (max-width: 1280px) {
  #app { grid-template-columns: 224px minmax(0, 1fr) 300px; }
  .brand-sub { display: none; }
  .doc-name { width: 140px; }
}
@media (max-width: 1040px) {
  #app { grid-template-columns: 190px minmax(0, 1fr) 272px; }
  .lib-list { grid-template-columns: 1fr; }
}

/* 打印/截图兜底 */
@media print {
  .topbar, .sidebar-left, .sidebar-right, .stage-toolbar, .statusbar, .ruler-h, .ruler-v { display: none !important; }
  #app { display: block; }
  .stage { padding: 0; background: #fff; }
}
