/* ============================================================
   起源计划 · Markdown 栏目样式（/markdown/）
   只被本栏目页面加载，不进全站 is46-ui.css，避免 270+ 页跟着换版本。
   设计变量沿用 is46-ui.css 的 --brand / --ink-* / --line。
   控件几何（按钮 34px、窄屏 44px、勾选胶囊垂直居中）与踩过的坑与
   /tupian/static/css/tupian.css 同源，那里已有注释说明「为什么必须有这几条」，
   这里照搬规则并保留关键注释，避免同一个坑在第二个栏目再踩一次。
   ============================================================ */

.i46-md-root { clear: both; }
.i46-md-root > * { box-sizing: border-box; }

/* ---------- 拖入 / 载入条 ---------- */
.i46-md-drop {
  position: relative;
  padding: 13px 15px;
  margin-bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  background: #f8fafc;
  border: 1px dashed #cfd8e8;
  border-radius: 12px;
  font-size: 13px;
  color: #4b5563;
  transition: border-color .15s, background .15s;
}
.i46-md-drop.is-on { border-color: var(--brand, #2563eb); background: #eff5ff; border-style: solid; }
.i46-md-drop input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.i46-md-drop-t { font-weight: 600; color: var(--ink, #1f2430); }

/* ---------- 参数面板 ---------- */
.i46-md-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: flex-start;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: #f6f8fc;
  border: 1px solid #e3e6ec;
  border-radius: 12px;
}
.i46-md-field { display: flex; flex-direction: column; gap: 5px; min-width: 116px; }
.i46-md-field.is-wide { flex: 1 1 100%; }
/* `:not(.i46-chip)` 是必需的：勾选胶囊也是 field 的直接子 <label>，
   被这条「标题行」规则命中会从 inline-flex 变成 baseline 对齐，勾选框和文字就不同中了。
   同族修复见 is46-ui.css 段 39 与 tupian.css。 */
.i46-md-field > label:not(.i46-chip), .i46-md-lbl {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: #4b5563;
}
.i46-md-field output { font-weight: 700; color: var(--brand, #2563eb); font-variant-numeric: tabular-nums; }
.i46-md-field select {
  height: 34px;
  padding: 0 9px;
  font-size: 13px;
  color: var(--ink, #1f2430);
  background: #fff;
  border: 1px solid #d7dce5;
  border-radius: 8px;
  font-family: inherit;
}
.i46-md-field input[type=text], .i46-md-field input[type=number], .i46-md-field input[type=search] {
  height: 34px;
  padding: 0 9px;
  font-size: 13px;
  color: var(--ink, #1f2430);
  background: #fff;
  border: 1px solid #d7dce5;
  border-radius: 8px;
  font-family: inherit;
}
.i46-md-field input:focus-visible, .i46-md-field select:focus-visible {
  outline: 2px solid var(--brand, #2563eb);
  outline-offset: 1px;
}
.i46-md-hint { font-size: 11.5px; color: var(--ink-3, #8b95a6); }
.i46-md-cgroup {
  flex: 1 1 100%;
  margin-top: 2px;
  padding-top: 8px;
  border-top: 1px dashed #dfe4ee;
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
}
.i46-md-cgroup:first-child { border-top: 0; padding-top: 0; }

/* 勾选胶囊：保持浅色 + 品牌描边（全局段 39 的「整块变蓝 + 白底勾选框」在勾选态很难看） */
.i46-md-bar .i46-chip { background: #fff; border-color: #dfe4ee; color: #374151; }
.i46-md-bar .i46-chip:hover { background: #f5f8ff; border-color: #c7d3ea; }
.i46-md-bar .i46-chip:has(input:checked) {
  background: #eaf1ff;
  border-color: var(--brand, #2563eb);
  color: var(--brand-dk, #1d4ed8);
}
.i46-md-bar .i46-chip:has(input:checked):hover { background: #dfeaff; }
.i46-md-bar .i46-chip:has(input:checked) input[type=checkbox] { accent-color: var(--brand, #2563eb); }

/* ---------- 按钮 ---------- */
.i46-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink, #1f2430);
  background: #fff;
  border: 1px solid #d7dce5;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.i46-btn:hover { background: #f3f6fb; border-color: #c3ccdb; }
.i46-btn:active { transform: translateY(1px); }
.i46-btn:focus-visible { outline: 2px solid var(--brand, #2563eb); outline-offset: 1px; }
.i46-btn[hidden] { display: none; }
.i46-btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }
.i46-btn.is-on { background: var(--brand, #2563eb); border-color: var(--brand, #2563eb); color: #fff; }
.i46-btn-primary {
  color: #fff;
  background: var(--brand, #2563eb);
  border-color: var(--brand, #2563eb);
  box-shadow: 0 1px 2px rgba(37, 99, 235, .28);
}
.i46-btn-primary:hover { background: var(--brand-dk, #1d4ed8); border-color: var(--brand-dk, #1d4ed8); }
.i46-btn-ghost { color: #4b5563; background: transparent; border-color: #dfe4ee; }
.i46-btn-ghost:hover { color: var(--ink, #1f2430); background: #f3f6fb; }
.i46-btn-sm { min-height: 28px; padding: 0 11px; font-size: 12.5px; }

.i46-md-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 10px; }
.i46-md-note { min-height: 18px; margin: 0 0 10px; font-size: 12.5px; color: var(--ink-3, #8b95a6); line-height: 1.6; }
.i46-md-note.is-warn { color: #92400e; }
.i46-md-note.is-err { color: #b91c1c; }
.i46-md-warn {
  padding: 9px 12px; margin: 0 0 12px;
  font-size: 12.5px; color: #92400e; background: #fff7ed;
  border: 1px solid #fed7aa; border-radius: 10px; line-height: 1.7;
}

/* ---------- 编辑 / 预览双栏 ---------- */
.i46-md-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 10px;
  padding: 8px 10px;
  background: #f6f8fc;
  border: 1px solid #e3e6ec;
  border-radius: 12px;
}
.i46-md-tools .i46-btn { min-height: 30px; padding: 0 10px; font-size: 12.5px; }
.i46-md-tsep { width: 1px; margin: 2px 4px; background: #dfe4ee; }

.i46-md-split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: stretch; }
.i46-md-split.is-single { grid-template-columns: 1fr; }
/* 两栏必须等高：早先是 align-items:start + 输入框固定 min-height:340，
   而预览按内容长到 74vh，于是「左边一截短、右边一大截」，看着像输入框被缩小了。
   现在 pane 做成列向 flex，输入框/预览各自 flex:1 撑满同一行高，
   行高由预览的 max-height(74vh) 与输入框的 min-height(340) 取大者决定，两边都内部滚动。 */
.i46-md-pane { display: flex; flex-direction: column; min-width: 0; }
.i46-md-pane > .i46-md-pane-hd { flex: none; }
.i46-md-pane > textarea, .i46-md-pane > .i46-md-preview { flex: 1 1 auto; min-height: 0; }
.i46-md-pane > .i46-md-actions { flex: none; }
.i46-md-pane-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 6px;
  font-size: 12.5px;
  font-weight: 700;
  color: #4b5563;
}
.i46-md-pane-hd .i46-md-pane-meta { font-weight: 400; color: var(--ink-3, #8b95a6); font-size: 11.5px; font-variant-numeric: tabular-nums; }

/* 输入区：全局 is46-ui.css 段 36 是
   `.i46-main textarea:not(.form-control):not(.json_input){... !important}`（权重 0,3,1），
   栏目里必须用同样形状但更多类名的选择器才压得住 ——
   只写 `.i46-md-root textarea` 会输给全局，实测 min-height 会变成 180px 而不是这里的 340px。
   窄屏还要把字号抬到 16px（iOS Safari <16px 输入框聚焦会自动放大整页），同样得带 !important。 */
.i46-main .i46-md-root textarea:not(.form-control):not(.json_input) {
  width: 100%;
  min-height: 340px;
  margin: 0;
  padding: 12px 14px !important;
  font-size: 14px !important;
  line-height: 1.7 !important;
  color: #1f2937;
  background: #fff;
  border: 1px solid #dbe3f0 !important;
  border-radius: 10px !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace !important;
  resize: vertical;
  tab-size: 4;
}
.i46-md-root textarea:focus {
  outline: 0;
  border-color: var(--brand, #2563eb) !important;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}
/* 变体同样要抬权重（全局那条是 0,3,1） */
.i46-main .i46-md-root textarea.is-out:not(.form-control) { background: #fbfcfe; color: #1f2430; }
/* 只读输出框不需要和输入框一样高：内容通常就几行，撑太高反而把结果推离视线 */
.i46-main .i46-md-root textarea.is-out:not(.form-control) { min-height: 190px; }
/* 「渲染效果」这类附属小预览不需要 340px 起高 */
.i46-md-preview.is-tight { min-height: 0; }
.i46-main .i46-md-root textarea.is-short:not(.form-control) { min-height: 120px; }
.i46-main .i46-md-root textarea.is-tall:not(.form-control) { min-height: 460px; }

/* 富文本粘贴盒（HTML→Markdown 的第二种输入） */
.i46-md-rt {
  min-height: 160px;
  max-height: 420px;
  overflow: auto;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.7;
  color: #1f2937;
  background: #fff;
  border: 1px dashed #cfd8e8;
  border-radius: 10px;
  outline: 0;
}
.i46-md-rt.is-on { border-style: solid; border-color: var(--brand, #2563eb); }
.i46-md-rt:empty::before { content: attr(data-ph); color: #9aa4b2; }

/* ---------- 预览（渲染结果，永远只放净化后的 HTML） ---------- */
.i46-md-preview {
  min-height: 340px;
  max-height: 74vh;
  overflow: auto;
  padding: 14px 18px;
  background: #fff;
  border: 1px solid #e3e6ec;
  border-radius: 10px;
  font-size: 15px;
  line-height: 1.78;
  color: #24292f;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.i46-md-preview > :first-child { margin-top: 0; }
.i46-md-preview h1, .i46-md-preview h2, .i46-md-preview h3,
.i46-md-preview h4, .i46-md-preview h5, .i46-md-preview h6 {
  margin: 22px 0 12px;
  font-weight: 700;
  line-height: 1.3;
  color: #1f2430;
}
.i46-md-preview h1 { font-size: 1.7em; padding-bottom: .3em; border-bottom: 1px solid #eaecef; }
.i46-md-preview h2 { font-size: 1.34em; padding-bottom: .3em; border-bottom: 1px solid #eaecef; }
.i46-md-preview h3 { font-size: 1.16em; }
.i46-md-preview h4 { font-size: 1em; }
.i46-md-preview h5 { font-size: .92em; }
.i46-md-preview h6 { font-size: .86em; color: #57606a; }
.i46-md-preview p { margin: 0 0 14px; }
.i46-md-preview a { color: var(--brand, #2563eb); text-decoration: none; }
.i46-md-preview a:hover { text-decoration: underline; }
.i46-md-preview ul, .i46-md-preview ol { margin: 0 0 14px; padding-left: 2em; }
.i46-md-preview li { margin: 3px 0; }
.i46-md-preview li > ul, .i46-md-preview li > ol { margin: 3px 0; }
.i46-md-preview li.task-item { list-style: none; margin-left: -1.4em; }
.i46-md-preview li.task-item input[type=checkbox] { margin: 0 .5em 0 0; vertical-align: -.1em; }
.i46-md-preview blockquote {
  margin: 0 0 14px;
  padding: 2px 14px;
  color: #57606a;
  background: #f8fafc;
  border-left: 4px solid #d0d7de;
  border-radius: 0 8px 8px 0;
}
.i46-md-preview blockquote > :last-child { margin-bottom: 0; }
.i46-md-preview code {
  padding: .2em .45em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 85%;
  background: #f2f4f8;
  border-radius: 6px;
}
.i46-md-preview pre {
  margin: 0 0 14px;
  padding: 13px 15px;
  overflow: auto;
  background: #f6f8fa;
  /* is46-ui.css 段「输出区」给全局 pre 定了深色底 + 浅色字（#e2e8f0）。
     这里把底色改成浅色却没改字色，代码块就会变成「浅灰底 + 浅灰字」看不见。
     必须显式写 color。 */
  color: #24292f;
  border: 1px solid #e8ebf2;
  border-radius: 9px;
  line-height: 1.6;
}
.i46-md-preview pre code { padding: 0; font-size: 13px; background: none; color: inherit; }
.i46-md-preview table { border-collapse: collapse; margin: 0 0 14px; display: block; max-width: 100%; overflow-x: auto; }
.i46-md-preview th, .i46-md-preview td { padding: 6px 13px; border: 1px solid #d0d7de; }
.i46-md-preview th { background: #f2f4f8; font-weight: 700; }
.i46-md-preview tr:nth-child(2n) td { background: #fbfcfe; }
.i46-md-preview img { max-width: 100%; height: auto; border-radius: 6px; }
.i46-md-preview hr { height: 1px; margin: 20px 0; border: 0; background: #d0d7de; }
.i46-md-preview del { color: #6e7781; }
.i46-md-preview .i46-md-empty { color: #9aa4b2; font-size: 13px; text-align: center; padding: 40px 0; }

/* ---------- 输出代码框（非 textarea 的只读展示） ---------- */
.i46-md-code {
  display: block;
  max-height: 300px;
  overflow: auto;
  padding: 11px 13px;
  margin: 0 0 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.65;
  color: #1f2430;
  background: #f7f8fb;
  border: 1px solid #e6e9f0;
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---------- 统计条 ---------- */
.i46-md-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 10px 0 0;
  padding: 9px 13px;
  background: #f6f8fc;
  border: 1px solid #e3e6ec;
  border-radius: 10px;
  font-size: 12.5px;
  color: #4b5563;
  font-variant-numeric: tabular-nums;
}
.i46-md-stat b { color: var(--ink, #1f2430); font-weight: 700; }
.i46-md-stat .i46-md-u { color: var(--ink-3, #8b95a6); font-weight: 400; }

/* ---------- 表格生成器 ---------- */
.i46-md-gridwrap { overflow-x: auto; margin: 0 0 10px; border: 1px solid #e3e6ec; border-radius: 10px; }
.i46-md-grid { border-collapse: collapse; width: 100%; min-width: 320px; }
.i46-md-grid th, .i46-md-grid td { padding: 0; border: 1px solid #eaeef4; }
.i46-md-grid thead th { background: #f6f8fc; padding: 6px; vertical-align: top; }
.i46-md-grid input, .i46-md-grid select {
  box-sizing: border-box;
  width: 100%;
  min-width: 92px;
  height: 32px;
  padding: 0 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink, #1f2430);
  background: #fff;
  border: 0;
  border-radius: 0;
}
.i46-md-grid input:focus { outline: 2px solid var(--brand, #2563eb); outline-offset: -2px; }
.i46-md-grid thead select { min-width: 62px; width: auto; height: 26px; font-size: 12px; padding: 0 4px; }
.i46-md-grid thead .i46-md-colhd { display: flex; gap: 4px; align-items: center; }
.i46-md-grid .i46-md-cellhd { font-size: 11.5px; font-weight: 700; color: #6b7280; white-space: nowrap; }
.i46-md-grid td.is-head input { font-weight: 600; }

/* ---------- 速查表 ---------- */
.i46-md-ref-grp { margin: 0 0 16px; }
.i46-md-ref-hd {
  display: flex; align-items: baseline; gap: 8px;
  margin: 0 0 8px; font-size: 14px; font-weight: 700; color: var(--ink, #1f2430);
}
.i46-md-ref-hd span { font-size: 12px; font-weight: 400; color: var(--ink-3, #8b95a6); }
.i46-md-ref-row {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr) minmax(0, 1.05fr) 104px;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid #eaeef4;
  border-radius: 10px;
  margin-bottom: 6px;
  background: #fff;
}
.i46-md-ref-row:hover { border-color: #d5deeb; background: #fbfcff; }
.i46-md-ref-name { font-size: 13px; font-weight: 600; color: var(--ink, #1f2430); }
.i46-md-ref-src {
  margin: 0;
  padding: 7px 9px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  color: #1f2430;
  background: #f7f8fb;
  border: 1px solid #e6e9f0;
  border-radius: 8px;
  white-space: pre;
}
.i46-md-ref-out {
  padding: 7px 9px;
  border: 1px solid #eef1f6;
  border-radius: 8px;
  background: #fff;
  overflow-x: auto;
}
.i46-md-ref-out .i46-md-preview { min-height: 0; max-height: none; overflow: visible; padding: 0; border: 0; background: none; font-size: 14px; line-height: 1.65; }
.i46-md-ref-out .i46-md-preview > * { margin: 0; }
.i46-md-ref-out .i46-md-preview > :not(:first-child) { margin-top: 8px; }
.i46-md-ref-pit { grid-column: 2 / -1; font-size: 12px; color: #92400e; }
.i46-md-ref-none { padding: 18px; text-align: center; color: #8b95a6; font-size: 13px; }
.i46-md-ref-ops { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.i46-md-ref-ops .i46-btn { width: 100%; }
.i46-md-key {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: #334155;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 5px;
}

/* ---------- 前后对照（整理页 / 转换页的「原样 HTML」提示） ---------- */
.i46-md-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: stretch; }
.i46-md-diffline {
  margin: 0;
  padding: 2px 8px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
  border-left: 3px solid #e5e7eb;
  background: #fbfcfe;
}
.i46-md-diffline.is-del { color: #b91c1c; background: #fef2f2; border-left-color: #fca5a5; }
.i46-md-diffline.is-ins { color: #15803d; background: #f0fdf4; border-left-color: #86efac; }
.i46-md-diffwrap { max-height: 320px; overflow: auto; border: 1px solid #e6e9f0; border-radius: 8px; margin: 0 0 10px; }

/* ---------- 轻提示 ---------- */
.i46-md-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 90;
  max-width: 86vw;
  padding: 9px 16px;
  font-size: 13px;
  color: #fff;
  background: rgba(17, 24, 39, .9);
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, .24);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s;
}
.i46-md-toast.is-on { opacity: 1; }

/* ---------- 窄屏的「编辑 / 预览」切换条（宽屏两栏并排，这条隐藏） ---------- */
.i46-md-viewrow { display: none; gap: 6px; margin: 0 0 10px; }
.i46-md-viewrow .i46-btn { min-height: 30px; padding: 0 14px; font-size: 12.5px; }
@media (max-width: 979.98px) { .i46-md-viewrow { display: flex; } }

/* 预览里被净化器丢了 src 的外链图片占位（不能让它变成一只破图） */
.i46-md-imgoff {
  display: inline-block;
  padding: 1px 9px;
  font-size: 12.5px;
  color: #8a6d1f;
  background: #fffbeb;
  border: 1px dashed #e2c878;
  border-radius: 6px;
}

/* ---------- 窄屏 ---------- */
@media (max-width: 979.98px) {
  /* 双栏在窄屏改成上下堆叠，并允许只显示一栏（编辑/预览切换），
     否则两个 min-height:340 的盒子叠起来，页面一屏什么都看不见。 */
  .i46-md-split { grid-template-columns: 1fr; }
  .i46-md-split.is-src-only .i46-md-pane.is-prev { display: none; }
  .i46-md-split.is-prev-only .i46-md-pane.is-src { display: none; }
  .i46-md-2col { grid-template-columns: 1fr; }
  .i46-main .i46-md-root textarea:not(.form-control):not(.json_input) { min-height: 260px; }
  /* 窄屏预览不能按内容无限长：整理页的前后两份预览实测会长到 1100+px，
     上下堆叠时对比要滚很久，所以给一个视口上限，超出部分各自内部滚动。 */
  .i46-md-preview { min-height: 260px; max-height: 70vh; overflow: auto; }
  /* 窄屏两栏是上下堆叠的，行高不再互相对齐；预览给个上限，避免长文档把编辑框顶出屏幕 */
  .i46-md-pane > textarea, .i46-md-pane > .i46-md-preview { flex: none; }
}

@media (max-width: 767.98px) {
  /* 触控基线 44px；与 is46-ui 段 24/39 对齐，别出现 34/38/40 三种高度 */
  .i46-md-field select,
  .i46-md-field input[type=text],
  .i46-md-field input[type=number],
  .i46-md-field input[type=search] { height: 44px; font-size: 16px; }
  .i46-chip { min-height: 44px; }
  .i46-btn { min-height: 44px; padding: 0 18px; }
  .i46-md-tools .i46-btn { min-height: 38px; padding: 0 12px; font-size: 13px; }
  .i46-btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
  /* iOS Safari：小于 16px 的输入框聚焦会自动放大整页 */
  .i46-main .i46-md-root textarea:not(.form-control):not(.json_input), .i46-md-rt { font-size: 16px !important; }
  .i46-md-ref-row { grid-template-columns: 1fr; gap: 6px; }
  .i46-md-ref-pit { grid-column: 1; }
  .i46-md-ref-row .i46-btn { width: 100%; }
  .i46-md-grid input { min-width: 110px; }
}
