/* editor.css — 配置文本编辑器原型样式表
 * 零依赖 / 自包含：无任何外部样式引入、无外部资源引用、无 web font、无构建。
 * 唯一目标：为 index.html（编辑器版）提供样式，与主应用观感一致：
 *   body 底色 #f4f6fa、白色卡片、圆角 6-8px、次要文字 #6b7280、主色 #2563eb。
 * 第一优先级：高亮层 #hl 与透明文字层 #ta 的两层文字逐像素重合。
 */

#b31EditorRoot {
  --bg: #f4f6fa;
  --card: #ffffff;
  --line: #e5e7eb;
  --line-soft: #f1f3f7;
  --ink: #1f2430;
  --ink-2: #374151;
  --muted: #6b7280;
  --muted-2: #9ca3af;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --radius: 7px;
  --radius-lg: 8px;
  --radius-sm: 6px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
  --font-size-code: 13px;
  --line-height-code: 20px;
  --pad-code-y: 8px;
  --pad-code-x: 12px;
  --gutter-w: 56px;
  --side-w: 320px;
}

/* ── 整页骨架 ───────────────────────────────────────────── */
#b31EditorRoot #ed {
  position: relative; /* #outline 的定位上下文（见文件末尾说明） */
  display: flex;
  flex-direction: column;
  height: 100vh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #f4f6fa;
  font-family: var(--font-ui);
}

/* ── 顶栏 ──────────────────────────────────────────────── */
#b31EditorRoot #topbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  flex: 0 0 auto;
}

#b31EditorRoot #topbar .brand {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  color: #1f2430;
  white-space: nowrap;
}

#b31EditorRoot #topbar .spacer, #b31EditorRoot .spacer {
  flex: 1 1 auto;
}

#b31EditorRoot #sampleSel {
  height: 26px;
  max-width: 260px;
  padding: 0 6px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #ffffff;
  color: #374151;
  font-family: var(--font-ui);
  font-size: 12px;
  line-height: 24px;
  cursor: pointer;
}

#b31EditorRoot #fileStat, #b31EditorRoot #lintSummary, #b31EditorRoot #dirty {
  white-space: nowrap;
}

/* ── 查找/替换条 ───────────────────────────────────────── */
#b31EditorRoot #findbar {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  flex: 0 0 auto;
  font-family: var(--font-ui);
  font-size: 12px;
}

#b31EditorRoot #fq, #b31EditorRoot #fr {
  height: 26px;
  padding: 0 8px;
  margin: 0;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #ffffff;
  color: #1f2430;
  font-family: var(--font-ui);
  font-size: 12px;
  line-height: 24px;
  box-sizing: border-box;
  outline: none;
}

#b31EditorRoot #fq {
  width: 200px;
  min-width: 120px;
}

#b31EditorRoot #fr {
  width: 160px;
  min-width: 100px;
}

#b31EditorRoot #fq:focus, #b31EditorRoot #fr:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

#b31EditorRoot #fcount {
  white-space: nowrap;
}

/* ── 主体：编辑器 + 侧栏 ───────────────────────────────── */
#b31EditorRoot #body {
  display: flex;
  flex-direction: row;
  flex: 1 1 auto;
  min-height: 0;
  gap: 0;
}

#b31EditorRoot #editorWrap {
  display: flex;
  flex-direction: row;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  margin: 8px 8px 8px 12px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* ── 行号栏 ────────────────────────────────────────────── */
#b31EditorRoot #gutter {
  width: 56px;
  flex: 0 0 56px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  text-align: right;
  padding: 8px 8px 8px 0;
  box-sizing: border-box;
  font-family: "Cascadia Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 20px;
  letter-spacing: 0;
  font-weight: 400;
  font-variant-ligatures: none;
  tab-size: 4;
  background: #fafbfe;
  border-right: 1px solid #e5e7eb;
  color: #9ca3af;
  user-select: none;
  -webkit-user-select: none;
}

#b31EditorRoot #gutter div.gl {
  display: block;
  height: 20px;
  line-height: 20px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  white-space: pre;
  font-family: "Cascadia Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
  font-size: 13px;
  letter-spacing: 0;
  font-weight: 400;
  font-variant-ligatures: none;
  tab-size: 4;
  color: inherit;
}

/* ── 编辑窗格 ──────────────────────────────────────────── */
#b31EditorRoot #pane {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  margin: 0;
  padding: 0;
  background: #ffffff;
}

/* ══════════════════════════════════════════════════════════
   #hl（高亮层）与 #ta（输入层）：严格同度量
   两块规则逐项重复书写（不使用合并选择器），确保任何一项
   padding / 字体 / 行高 / 字距 / 断行 / 盒模型 都完全一致。
   ══════════════════════════════════════════════════════════ */

/* 高亮层：在 textarea 之下，只负责背景色块与文字着色 */
#b31EditorRoot #hl {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  border: 0;
  padding: 8px 12px;
  font-family: "Cascadia Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 20px;
  letter-spacing: 0;
  font-weight: 400;
  font-variant-ligatures: none;
  tab-size: 4;
  white-space: pre;
  word-wrap: normal;
  overflow-wrap: normal;
  box-sizing: border-box;
  overflow: auto;
  z-index: 1;
  pointer-events: none;
  color: #1f2430; /* 兜底：未被 token 覆盖的文字也是这个颜色 */
  background: #fff;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#b31EditorRoot #hl::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

/* 输入层：在最上，背景透明，文字可见；用户看到的是 #ta 的字 + #hl 的底 */
#b31EditorRoot #ta {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  border: 0;
  padding: 8px 12px;
  font-family: "Cascadia Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 20px;
  letter-spacing: 0;
  font-weight: 400;
  font-variant-ligatures: none;
  tab-size: 4;
  white-space: pre;
  word-wrap: normal;
  overflow-wrap: normal;
  box-sizing: border-box;
  overflow: auto;
  z-index: 2;
  background: transparent;
  color: #1f2430;
  -webkit-text-fill-color: #1f2430;
  caret-color: #1f2430;
  resize: none;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

/* ── 高亮层内部：行块 ──────────────────────────────────── */
#b31EditorRoot #hl .ln {
  display: block;
  min-width: 100%;
  height: 20px;
  min-height: 20px;
  max-height: 20px;
  line-height: 20px;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  white-space: pre;
  overflow: hidden;
}

#b31EditorRoot #hl .ln.cur {
  background: #eef2ff;
}

/* ── 查找命中 ──────────────────────────────────────────── */
#b31EditorRoot #hl .ln .mt {
  background: #fde68a;
  border-radius: 2px;
}

#b31EditorRoot #hl .ln .mt.cur {
  background: #fca5a5;
}

/* ── 语法高亮 token ────────────────────────────────────── */
#b31EditorRoot #hl .sec {
  color: #7c3aed;
  font-weight: 700;
}

#b31EditorRoot #hl .k {
  color: #0f766e;
}

#b31EditorRoot #hl .eq {
  color: #9ca3af;
}

#b31EditorRoot #hl .v {
  color: #1f2430;
}

#b31EditorRoot #hl .url {
  color: #2563eb;
}

#b31EditorRoot #hl .cm {
  color: #94a3b8;
  font-style: italic;
}

#b31EditorRoot #hl .dv {
  color: #cbd5e1;
}

#b31EditorRoot #hl .bare {
  color: #b45309;
}

#b31EditorRoot #hl .ws {
  color: #e5e7eb;
}

/* ── 右侧栏 ────────────────────────────────────────────── */
/* 注意：#side 故意不设 position:relative —— 让 #outline 的包含块落到
   #ed（position:relative），浮层才能锚在顶栏「大纲」按钮下方并且不被
   #side 的 overflow 裁剪/滚动。 */
#b31EditorRoot #side {
  width: var(--side-w);
  flex: 0 0 var(--side-w);
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  background: #ffffff;
  border-left: 1px solid #e5e7eb;
  overflow-y: auto;
  overflow-x: hidden;
  font-family: var(--font-ui);
}

#b31EditorRoot #lintHead {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 8px 12px;
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  font-size: 12px;
  font-weight: 600;
  color: #374151;
}

#b31EditorRoot #lintList {
  margin: 0;
  padding: 0;
  font-family: var(--font-ui);
}

#b31EditorRoot .lrow {
  display: grid;
  grid-template-columns: 18px 40px 52px minmax(0, 1fr);
  gap: 6px;
  padding: 4px 8px;
  border-bottom: 1px solid #f1f3f7;
  cursor: pointer;
  font-size: 12px;
  line-height: 18px;
  color: #374151;
  background: transparent;
}

#b31EditorRoot .lrow:hover {
  background: #f8fafc;
}

#b31EditorRoot .lrow.active {
  background: #eff6ff;
  box-shadow: inset 3px 0 0 #2563eb;
}

#b31EditorRoot .lrow .sev {
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  white-space: nowrap;
}

#b31EditorRoot [data-sev="error"] {
  color: #dc2626;
}

#b31EditorRoot [data-sev="warning"] {
  color: #d97706;
}

#b31EditorRoot [data-sev="info"] {
  color: #64748b;
}

#b31EditorRoot .lrow .lcode, #b31EditorRoot .lrow .lno {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#b31EditorRoot .lrow .lmsg {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── 大纲浮层 ──────────────────────────────────────────── */
#b31EditorRoot #outline {
  position: absolute;
  right: 16px;
  top: 52px;
  width: 320px;
  max-height: 60vh;
  overflow: auto;
  margin: 0;
  padding: 4px 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  z-index: 50;
  font-family: var(--font-ui);
}

#b31EditorRoot #outline .oitem {
  padding: 4px 10px;
  font-size: 12px;
  line-height: 18px;
  cursor: pointer;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#b31EditorRoot #outline .oitem:hover {
  background: #f1f5f9;
}

/* ── 状态栏 ────────────────────────────────────────────── */
#b31EditorRoot #statusbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  height: 28px;
  margin: 0;
  padding: 0 12px;
  background: #ffffff;
  border-top: 1px solid #e5e7eb;
  font-size: 11px;
  line-height: 28px;
  white-space: nowrap;
  overflow: hidden;
}

/* ── 右下角提示浮层 ────────────────────────────────────── */
#b31EditorRoot #toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 99;
  max-width: 320px;
  padding: 8px 14px;
  background: #1f2937;
  color: #ffffff;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.24);
  font-family: var(--font-ui);
  font-size: 12px;
  line-height: 18px;
}

/* ── 通用小件 ──────────────────────────────────────────── */
#b31EditorRoot .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 10px;
  margin: 0;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #ffffff;
  color: #374151;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 400;
  line-height: 18px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  box-sizing: border-box;
}

#b31EditorRoot .btn:hover {
  background: #f3f4f6;
  border-color: #cbd5e1;
}

#b31EditorRoot .btn:active {
  background: #e5e7eb;
}

#b31EditorRoot .btn:focus-visible {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}

#b31EditorRoot .btn:disabled, #b31EditorRoot .btn[disabled] {
  opacity: 0.55;
  cursor: default;
}

#b31EditorRoot .btn.sm {
  padding: 3px 8px;
  font-size: 12px;
  line-height: 18px;
  border-radius: 6px;
}

#b31EditorRoot .btn.primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #ffffff;
}

#b31EditorRoot .btn.primary:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

#b31EditorRoot .btn.primary:active {
  background: #1e40af;
  border-color: #1e40af;
}

#b31EditorRoot .muted {
  color: #6b7280;
  font-size: 12px;
}

#b31EditorRoot .chk {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-ui);
  font-size: 12px;
  line-height: 18px;
  color: #374151;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

#b31EditorRoot .chk input[type="checkbox"] {
  margin: 0;
  width: 13px;
  height: 13px;
  accent-color: #2563eb;
  cursor: pointer;
}

/* ══════════════════════════════════════════════════════════
   自动换行开关（真实双向开关）
   开：#ta 折行（pre-wrap）+ 高亮层 #hl 关闭 + 行号栏按折行行数重排行高
   关（默认）：white-space:pre / wrap="off" / 高亮层开 / 长行横向滚动
   ══════════════════════════════════════════════════════════ */

/* 开关的真实按下 / 选中视觉状态（class 与 aria-pressed 双写，避免「看起来开着没生效」） */
#b31EditorRoot #btnWrap::after {
  content: "：关";
  opacity: 0.75;
}

#b31EditorRoot #btnWrap.on, #b31EditorRoot #btnWrap[aria-pressed="true"] {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #ffffff;
  font-weight: 600;
  box-shadow: inset 0 2px 5px rgba(15, 23, 42, 0.35);
}

#b31EditorRoot #btnWrap.on::after, #b31EditorRoot #btnWrap[aria-pressed="true"]::after {
  content: "：开";
  opacity: 1;
}

#b31EditorRoot #btnWrap.on:hover, #b31EditorRoot #btnWrap[aria-pressed="true"]:hover {
  background: #1e40af;
  border-color: #1e40af;
}

/* 换行模式下的输入层：折行显示，不再横向滚动 */
#b31EditorRoot #ta.wrap-on {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow-x: hidden;
}

/* 换行模式下关闭语法高亮层（display:none，既不着色也不参与布局） */
#b31EditorRoot #hl.off {
  display: none;
}

/* 折行测量镜层：与 #ta 逐项同度量的不可见副本，用于求每个逻辑行的视觉行数 */
#b31EditorRoot #wmirror {
  position: absolute;
  top: 0;
  left: 0;
  margin: 0;
  border: 0;
  visibility: hidden;
  pointer-events: none;
  overflow: hidden;
  box-sizing: border-box;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  z-index: 0;
  color: transparent;
}

#b31EditorRoot #wmirror.off {
  display: none;
}

#b31EditorRoot #wmirror>div {
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* 换行模式下状态栏里的那句明确提示 */
#b31EditorRoot #wrapNote {
  color: #b45309;
  font-size: 12px;
  line-height: 18px;
  white-space: nowrap;
}

#b31EditorRoot .hidden {
  display: none;
}


/* ══════════════════════════════════════════════════════════
   追加：嵌入宿主弹窗（#ccdEditorHost）时的布局收敛
   —— 取消原型的 100vh，让编辑器填满宿主给的盒子；
      hidden 属性在作者样式下必须仍然是 display:none。
   ══════════════════════════════════════════════════════════ */
#b31EditorRoot[hidden] {
  display: none;
}

#b31EditorRoot {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#b31EditorRoot #ed {
  height: 100%;
  min-height: 0;
  flex: 1 1 auto;
}

#b31EditorRoot #body {
  min-height: 0;
  overflow-x: hidden;
}

/* 只读态（handle.setEditable(false)）：去掉光标，不影响任何度量 */
#b31EditorRoot.b31-readonly #ta {
  caret-color: transparent;
}

/* #btnLint：折叠右侧校验面板（display:none → 编辑区自动占满，无横向溢出） */
#b31EditorRoot.b31-lint-closed #side {
  display: none;
}

#b31EditorRoot #btnLint.on {
  border-color: #2563eb;
  color: #2563eb;
  background: #eff6ff;
}

/* 窄屏兜底：右侧校验栏收窄，避免挤压编辑区 */
@media (max-width: 1320px) {
  #b31EditorRoot #side {
    flex: 0 0 260px;
    width: 260px;
  }
}
