/* ============ 基础 ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #faf6fd;
  --panel: #ffffff;
  --line: #ece1f7;
  --line-soft: #f4ecfb;
  --text: #2e2440;
  --muted: #9b8cab;
  --primary: #9333ea;
  --primary-hover: #7e22ce;
  --primary-soft: #f8ecff;
  --accent: #ec4899;
  --danger: #c0503e;
  --brand: #9333ea;
  --brand-ink: #ffffff;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(88, 28, 135, .06);
  --shadow: 0 2px 6px rgba(88, 28, 135, .06), 0 14px 40px rgba(88, 28, 135, .09);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

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

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #ddc9ee; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #c9abe4; }
::-webkit-scrollbar-track { background: transparent; }

.app { height: 100vh; display: flex; flex-direction: column; }

/* ============ 顶栏 ============ */
.topbar {
  height: 62px;
  flex: 0 0 62px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 18px;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }

.brand-mark {
  width: 34px; height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #9333ea, #d946ef 55%, #ec4899);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: 0;
  box-shadow: 0 3px 8px rgba(88, 28, 135, .16);
  transition: background .2s;
}

.brand-info h1 { font-size: 15px; font-weight: 600; letter-spacing: .3px; line-height: 1.3; }
.brand-info p { font-size: 12px; color: var(--muted); letter-spacing: .2px; }

.style-tabs {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 2px;
  scrollbar-width: none;
}
.style-tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 14px;
  color: #8b7aa6;
  background: transparent;
  border: 1px solid transparent;
  white-space: nowrap;
  transition: all .16s ease;
  position: relative;
}
.tab:hover { background: #eee3f9; color: var(--text); }
.tab.active {
  background: linear-gradient(135deg, #9333ea, #d946ef 55%, #ec4899);
  color: #fff;
  border-color: transparent;
}
.tab.custom::after {
  content: "";
  position: absolute; top: 5px; right: 6px;
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--accent);
}

.actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.btn {
  padding: 8px 15px;
  border-radius: 8px;
  font-size: 14px;
  transition: all .16s ease;
  white-space: nowrap;
}
.btn.ghost { background: #f7f1fc; color: #6d5b8a; }
.btn.ghost:hover { background: #eee3f9; }
.btn.primary {
  background: linear-gradient(135deg, #9333ea, #d946ef 55%, #ec4899);
  color: #fff;
  box-shadow: 0 2px 10px rgba(147, 51, 234, .35);
}
.btn.primary:hover { filter: brightness(1.08); box-shadow: 0 3px 14px rgba(147, 51, 234, .45); }
.btn.primary:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ============ 工作区 ============ */
.workspace {
  flex: 1 1 auto;
  display: grid;
  /* 右栏只留够放下 375px 手机预览的宽度，其余全给编辑区 */
  grid-template-columns: minmax(360px, 1fr) 432px;
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}

.pane {
  background: var(--panel);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.pane-head {
  height: 50px;
  flex: 0 0 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--line-soft);
}

.pane-label {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--muted);
  white-space: nowrap;
  flex: 0 0 auto;
}

/* 撤销 / 重做 */
.pane-head-left { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.hist-btns { display: flex; align-items: center; gap: 3px; }
.hist-btns button {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  color: #8b7aa6;
  background: #f7f1fc;
  transition: all .14s;
}
.hist-btns button:hover:not(:disabled) { background: var(--primary-soft); color: var(--primary); }
.hist-btns button:active:not(:disabled) { transform: translateY(1px); }
.hist-btns button:disabled { opacity: .32; cursor: default; }
/* 撤销/重做与「整理」之间的一道细分隔 */
.hist-btns .hist-sep { width: 1px; height: 15px; margin: 0 3px; background: #ece1f8; }
.hist-btns button.hist-tidy { color: var(--primary); background: var(--primary-soft); }

.quick-insert {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 0 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.quick-insert::-webkit-scrollbar { display: none; }
.quick-insert button {
  min-width: 30px; height: 30px;
  padding: 0 9px;
  border-radius: 7px;
  font-size: 14px;
  color: #8b7aa6;
  background: #f7f1fc;
  white-space: nowrap;
  flex: 0 0 auto;
  transition: all .14s;
}
.quick-insert button:hover { background: var(--primary-soft); color: var(--primary); }

/* 编辑栏头：左边标签与历史按钮，右边工具栏靠右，中间自动留白 */
.editor-head { justify-content: flex-start; gap: 10px; }
.editor-head .quick-insert { margin-left: auto; }

/* 编辑栏顶部的主题色圆点 */
.mini-themes {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  margin-left: 10px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}
.mini-theme {
  width: 17px; height: 17px;
  min-width: 0;
  padding: 0;
  border-radius: 50%;
  background: #eee;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
  transition: transform .12s, box-shadow .12s;
}
.mini-theme:hover { transform: scale(1.18); background: #eee; }
.mini-theme.active {
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.14), 0 0 0 2px #fff, 0 0 0 3.5px #23231f;
}

/* ============ 编辑区 ============ */
#editor {
  flex: 1 1 auto;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 14px;
  line-height: 1.85;
  font-size: 15px;
  color: #3a3a3a;
  background: transparent;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

#editor.drop {
  background: #fffdf2;
  box-shadow: inset 0 0 0 2px var(--brand);
}

.pane-foot {
  flex: 0 0 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-top: 1px solid var(--line-soft);
  font-size: 12.5px;
  color: var(--muted);
}
.pane-foot .foot-left { display: flex; align-items: center; gap: 10px; }
/* 自动保存提示：存完淡入，几秒后淡出，不占版面不打断输入 */
.pane-foot .save-hint {
  font-size: 12px;
  color: #b5afa2;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .3s;
}
.pane-foot .save-hint.show { opacity: 1; }
.pane-foot .hint {
  color: #b5afa2;
  letter-spacing: .2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* ============ 预览区 ============ */
.preview-scroll {
  flex: 1 1 auto;
  overflow: auto;
  background:
    radial-gradient(circle at 1px 1px, #e2d2f4 1px, transparent 0) 0 0 / 22px 22px,
    #fbf8fe;
  padding: 26px 22px 40px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.device {
  width: 375px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 18px 48px rgba(0,0,0,.1);
  overflow: hidden;
  transition: width .22s ease;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 200px);
}

/* 整屏滚动：标题、正文、底部数据条一起滚 */
.wx-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
}
.wx-scroll::-webkit-scrollbar { width: 5px; }

/* 公众号标题区：模拟手机端文章头部 */
.wx-head {
  padding: 28px 16px 0;
}

.wx-title {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.42;
  letter-spacing: .3px;
  color: #191919;
  word-break: break-word;
}

.wx-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 14px;
  font-size: 13px;
  line-height: 1.5;
}
.wx-date { color: #9a9a96; letter-spacing: .2px; }
.wx-account { color: #576b95; }

/* 正文容器：左右各留 16px，等同微信正文安全区 */
.device-body {
  padding: 22px 16px 40px;
  overflow-x: hidden;
}

/* 底部操作栏：固定在卡片底部，左下阅读量、右下在看与赞 */
.wx-foot {
  flex: 0 0 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  border-top: 1px solid #f0efec;
  background: #fff;
  font-size: 12px;
  color: #a8a8a4;
  letter-spacing: .2px;
}
.wx-foot-act { color: #b3b3af; }

/* ============ 抽屉 ============ */
.mask {
  position: fixed; inset: 0;
  background: rgba(64, 28, 98, .3);
  backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden;
  transition: all .22s ease;
  z-index: 40;
}
.mask.show { opacity: 1; visibility: visible; }

.drawer {
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  width: 720px;
  max-width: 94vw;
  background: var(--panel);
  box-shadow: 8px 0 48px rgba(64, 28, 98, .14);
  display: flex;
  flex-direction: column;
  transform: translateX(-102%);
  transition: transform .28s cubic-bezier(.32, .72, 0, 1);
  z-index: 50;
}
.drawer.show { transform: translateX(0); }

.drawer-head {
  height: 70px;
  flex: 0 0 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { font-size: 16px; font-weight: 600; }
.drawer-head p { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* 样式重命名：副标题右侧的小铅笔 */
.drawer-sub { display: flex; align-items: center; gap: 6px; }
.rename-btn {
  width: 21px; height: 21px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 5px;
  color: #b49fd6;
  transition: all .14s;
}
.rename-btn:hover { background: #f1eee8; color: var(--primary); }

.icon-btn {
  width: 30px; height: 30px;
  border-radius: 7px;
  color: #8d8779;
  font-size: 16px;
  transition: all .14s;
}
.icon-btn:hover { background: #f5edfc; color: var(--text); }

.drawer-body {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 176px 1fr;
  overflow: hidden;
}

.el-nav {
  border-right: 1px solid var(--line-soft);
  overflow-y: auto;
  padding: 10px 8px;
  background: #fbfaf8;
}

.el-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 7px;
  font-size: 14px;
  color: #5d584b;
  cursor: pointer;
  transition: all .14s;
  margin-bottom: 2px;
  user-select: none;
}
.el-item:hover { background: #f4eafb; }
.el-item.active { background: linear-gradient(135deg, #9333ea, #c026d3); color: #fff; font-weight: 500; }
.el-item.active .el-dot { background: #fff; opacity: .85; }

.el-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--primary);
  flex: 0 0 auto;
  transition: all .14s;
}
.el-item.off .el-dot { background: #d6c6ea; }
.el-item.off { color: #ab9dc4; }
.el-item.off.active { color: #fff; opacity: .82; }
.el-item.off.active .el-dot { background: #fff; }

.el-name { flex: 1; }

.el-eye {
  font-size: 12px;
  color: #b5afa2;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}
.el-item.active .el-eye { color: rgba(255,255,255,.72); }
.el-eye:hover { background: rgba(0,0,0,.06); }

.el-panel {
  overflow-y: auto;
  padding: 18px 22px 40px;
}

.panel-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}
.panel-desc {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.6;
}

.group-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.2px;
  color: #ab9dc4;
  margin: 20px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-soft);
}
.group-title:first-of-type { margin-top: 8px; }

.field {
  display: grid;
  grid-template-columns: 88px 1fr;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
}
.field-label { font-size: 13.5px; color: #615c4f; }
.field-ctl { display: flex; align-items: center; gap: 8px; min-width: 0; }

/* 控件 */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1 1 auto;
  height: 4px;
  border-radius: 4px;
  background: #e9d9f8;
  outline: none;
  min-width: 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--primary);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.14);
  transition: transform .12s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.12); }

.range-val {
  flex: 0 0 46px;
  text-align: right;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

input[type="text"], input[type="number"], select, textarea.ctl {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfaf8;
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 14px;
  outline: none;
  transition: all .14s;
  min-width: 0;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus, textarea.ctl:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(0,0,0,.06);
}
textarea.ctl { resize: vertical; min-height: 62px; line-height: 1.6; }
select { cursor: pointer; appearance: none; background-image: none; padding-right: 26px; }

.color-ctl {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}
input[type="color"] {
  width: 34px; height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 2px;
  background: #fff;
  cursor: pointer;
  flex: 0 0 auto;
}
.color-hex {
  flex: 1 1 auto;
  border: 1px solid var(--line);
  background: #fbfaf8;
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  outline: none;
  min-width: 0;
  transition: all .14s;
}
.color-hex:focus { border-color: var(--primary); background: #fff; }

.seg {
  display: flex;
  background: #f4f1ec;
  border-radius: 7px;
  padding: 2px;
  gap: 2px;
}
.seg button {
  flex: 1 1 auto;
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 13px;
  color: #8b7aa6;
  transition: all .14s;
  white-space: nowrap;
}
.seg button.active { background: #fff; color: var(--primary); font-weight: 600; box-shadow: var(--shadow-sm); }

/* 主题色色块 */
.theme-seg { display: flex; align-items: center; gap: 9px; }
.theme-dot {
  width: 24px; height: 24px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.14);
  transition: transform .12s, box-shadow .12s;
  cursor: pointer;
}
.theme-dot:hover { transform: scale(1.1); }
.theme-dot.active {
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.14), 0 0 0 2px #fff, 0 0 0 4px #23231f;
}
.theme-name { font-size: 13px; color: var(--muted); }

.switch {
  width: 38px; height: 22px;
  border-radius: 11px;
  background: #ddd8cc;
  position: relative;
  transition: background .18s;
  flex: 0 0 auto;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform .18s;
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
}
.switch.on { background: var(--primary); }
.switch.on::after { transform: translateX(16px); }

.drawer-foot {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 12px 22px 14px;
  border-top: 1px solid var(--line);
  background: #fbfaf8;
}
.drawer-foot-btns {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

/* 底部左下角：DeepSeek API Key */
.ai-key { display: flex; align-items: center; gap: 8px; }
.ai-key-label {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  flex: 0 0 auto;
  letter-spacing: .2px;
}
.ai-key input {
  flex: 1 1 auto;
  min-width: 0;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  color: var(--text);
  font-family: ui-monospace, Menlo, monospace;
  transition: border-color .14s, box-shadow .14s;
}
.ai-key input::placeholder { color: #b8b2c4; font-family: var(--font, inherit); }
.ai-key input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(147, 51, 234, .1);
}
.ai-key input.saved { border-color: #86c98a; box-shadow: 0 0 0 3px rgba(134, 201, 138, .16); }
.ai-key .btn { flex: 0 0 auto; height: 32px; padding: 0 14px; }
/* 测试连接的三种临时状态 */
.ai-key .btn.busy { opacity: .62; cursor: default; }
.ai-key .btn.ok { color: #2f8f46; border-color: #9ed3a8; background: #f2faf4; }
.ai-key .btn.bad { color: #c0392b; border-color: #efb3ab; background: #fdf3f1; }

/* ============ AI 智校抽屉（右侧） ============ */
.ai-drawer {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: 440px;              /* 兜底值；打开时由 alignAiDrawer() 按预览框左边缘重算 */
  max-width: 94vw;
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -10px 0 46px rgba(64, 28, 98, .16);
  display: flex;
  flex-direction: column;
  transform: translateX(104%);
  transition: transform .28s cubic-bezier(.32, .72, 0, 1);
  z-index: 55;
}
.ai-drawer.show { transform: translateX(0); }

.ai-head {
  flex: 0 0 70px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(135deg, #fbf6ff, #fff);
}
.ai-head h2 { font-size: 16px; font-weight: 600; letter-spacing: .5px; }
.ai-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

.ai-body { flex: 1 1 auto; overflow-y: auto; padding: 18px 20px 26px; }

.ai-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: #fbfaf8;
}
.ai-foot .ai-hint { font-size: 12px; color: #a8a29b; }

/* 概览卡 */
.ai-summary {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, #f7f0fe, #fdf2f8);
  border: 1px solid #efe2fa;
  margin-bottom: 18px;
}
.ai-score { text-align: center; flex: 0 0 auto; min-width: 56px; }
.ai-score b { display: block; font-size: 26px; line-height: 1.1; color: var(--primary); font-weight: 600; }
.ai-score span { font-size: 11.5px; color: var(--muted); }
.ai-summary-text { font-size: 13px; line-height: 1.7; color: #5d5a55; margin: 0; }

/* 分组 */
.ai-group { margin-bottom: 18px; }
.ai-group-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 9px;
}
.ai-count {
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  color: #fff;
}
.ai-group[data-type="typo"] .ai-group-title { color: #a32d2d; }
.ai-group[data-type="typo"] .ai-count { background: #e24b4a; }
.ai-group[data-type="punct"] .ai-group-title { color: #854f0b; }
.ai-group[data-type="punct"] .ai-count { background: #ba7517; }
.ai-group[data-type="wording"] .ai-group-title { color: #185fa5; }
.ai-group[data-type="wording"] .ai-count { background: #378add; }
.ai-group[data-type="fact"] .ai-group-title { color: #534ab7; }
.ai-group[data-type="fact"] .ai-count { background: #7f77dd; }
.ai-group[data-type="risk"] .ai-group-title { color: #501313; }
.ai-group[data-type="risk"] .ai-count { background: #a32d2d; }

.ai-card {
  border: 1px solid #eee9f2;
  border-left: 3px solid #d9d3e2;
  border-radius: 10px;
  padding: 11px 13px;
  margin-bottom: 9px;
  background: #fff;
}
.ai-card[data-level="high"] { border-left-color: #e24b4a; background: #fffafa; }
.ai-card[data-level="mid"] { border-left-color: #ef9f27; }
.ai-card[data-level="low"] { border-left-color: #cfc8dd; }

.ai-quote {
  font-size: 13px;
  line-height: 1.7;
  color: #3a3a3a;
  background: #f7f4fb;
  border-radius: 6px;
  padding: 6px 9px;
  margin: 0 0 8px;
  word-break: break-word;
}
.ai-quote::before { content: "「"; color: #b9a8d0; }
.ai-quote::after { content: "」"; color: #b9a8d0; }
.ai-issue { font-size: 13px; line-height: 1.7; color: #4a4a48; margin: 0 0 6px; }
.ai-suggest { font-size: 13px; line-height: 1.7; color: #1f7a4d; margin: 0; word-break: break-word; }
.ai-suggest em {
  font-style: normal;
  font-size: 11.5px;
  color: #fff;
  background: #1d9e75;
  border-radius: 4px;
  padding: 1px 6px;
  margin-right: 6px;
  vertical-align: 1px;
}

/* 状态：加载中 / 空 / 出错 */
.ai-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 56px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.7;
}
.ai-spinner {
  width: 26px; height: 26px;
  border: 2.5px solid #ece0f9;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: aiSpin .85s linear infinite;
}
@keyframes aiSpin { to { transform: rotate(360deg); } }

.ai-tip {
  padding: 34px 18px;
  text-align: center;
  font-size: 13.5px;
  line-height: 1.85;
  color: var(--muted);
}
.ai-tip b { color: var(--primary); font-weight: 600; }

.ai-err {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #fdeceb;
  border: 1px solid #f5c4c1;
  color: #98231f;
  font-size: 13px;
  line-height: 1.7;
  word-break: break-word;
}
/* 排查用的原始返回：默认折叠，不打扰正常使用 */
.ai-raw { margin: -6px 0 14px; }
.ai-raw summary {
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 0;
}
.ai-raw pre {
  margin: 6px 0 0;
  padding: 10px 12px;
  max-height: 220px;
  overflow: auto;
  background: #f7f5fa;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 11.5px;
  line-height: 1.6;
  color: #5b5470;
  white-space: pre-wrap;
  word-break: break-all;
}

.ai-meta { font-size: 12px; color: #a8a29b; margin-top: 14px; text-align: center; }


/* ============ 附加控件 ============ */
.mini-link {
  margin-left: 8px;
  font-size: 14px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
  flex: 0 0 auto;
  transition: all .14s;
}
.mini-link:hover { background: #f5edfc; color: var(--primary); }
.mini-link.active { color: var(--primary); font-weight: 600; }

/* ---------- 预览夜间模式 ----------
   只模拟"屏幕内"的变化：手机屏幕（文章内容 + 底部状态栏）变暗，
   屏幕外的网页底色保持日间的米色点纹。
   色值经过校准：白色 invert(.92) 后正好是 #141414；
   图片额外加反补偿滤镜（invert(1) + hue-rotate(180) + contrast(1.19)），
   与外层滤镜叠加后数学上互相抵消，图片按原色显示。 */
.preview-scroll.night .device {
  background: #141414;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 18px 48px rgba(0, 0, 0, .5);
}
.preview-scroll.night .wx-scroll {
  filter: invert(.92) hue-rotate(180deg);
}
.preview-scroll.night .wx-scroll img {
  filter: invert(1) hue-rotate(180deg) contrast(1.19);
}
.preview-scroll.night .wx-foot {
  background: #141414;
  border-top-color: #26262a;
  color: #8a8a90;
}
.preview-scroll.night .wx-foot-act { color: #6e6e74; }

/* 日间/夜间切换小图标（放"预览"标签后面） */
.mode-btn {
  width: 28px; height: 28px;
  margin-left: -4px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; border-radius: 7px;
  color: var(--muted); cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.mode-btn:hover { background: #f5edfc; color: var(--primary); }
.mode-btn.on { color: var(--primary); }

.btn.danger { color: var(--danger); }
.btn.danger:hover { background: #fbeeeb; }

.drawer-foot .spacer { flex: 1 1 auto; }

/* ============ 命名对话框 ============ */
.dialog {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 340px;
  background: #fff;
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 24px 64px rgba(64, 28, 98, .22);
}
.dialog h3 { font-size: 16px; font-weight: 600; margin-bottom: 14px; }
.dlg-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
  background: #fbfaf8;
  transition: all .14s;
}
.dlg-input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(0,0,0,.06); }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ============ 导入对话框 ============ */
.mask.import-mask { z-index: 85; }

.import-dialog {
  width: 480px;
  max-width: 92vw;
  padding: 24px;
}

.import-dialog .dlg-desc,
.dialog .dlg-desc {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.7;
  margin: -8px 0 16px;
}

.import-input-row { display: flex; gap: 8px; }
.import-input-row .dlg-input { flex: 1 1 auto; }
.import-input-row .btn { flex: 0 0 auto; padding: 0 18px; }
.import-style-row { margin-top: 10px; }

.import-status {
  font-size: 13.5px;
  line-height: 1.7;
  margin-top: 10px;
  min-height: 0;
  color: var(--muted);
}
.import-status:empty { margin-top: 0; }
.import-status.loading { color: var(--primary); }
.import-status.err { color: var(--danger); }
.import-status.ok { color: var(--primary); }

.import-result { margin-top: 16px; }

.import-summary {
  background: #f8f6f2;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 13.5px;
  line-height: 1.9;
  color: #5d584b;
}
.import-summary .imp-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.5;
}
.import-summary .imp-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.imp-tag {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.imp-tag b { color: var(--primary); font-weight: 600; }

.import-note { margin-top: 12px; font-size: 13px; color: var(--muted); line-height: 1.7; }

/* ============ Toast ============ */
/* 底色与字色跟着当前主题色走（--brand / --brand-ink 由 app.js 的 syncBrand 实时写入），
   固定在屏幕正中间，切换主题后提示条立刻换色。 */
.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(.94);
  max-width: min(560px, 76vw);
  background: var(--brand);
  color: var(--brand-ink);
  padding: 13px 24px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.65;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, transform .2s ease, visibility .2s;
  z-index: 90;
  pointer-events: none;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .26), 0 0 0 1px rgba(255, 255, 255, .18) inset;
}
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, -50%) scale(1); }

/* ============ 精简界面：暂时收起的按钮 ============ */
/* 恢复办法：把 index.html 里 <body class="lean"> 的 lean 去掉，这几个按钮就全部回来 */
body.lean #btnDrafts,
body.lean #btnImport,
body.lean #btnSaveTop,
body.lean #btnReset,
body.lean #btnExportJson { display: none !important; }

/* ============ 响应式 ============ */
/* 窗口偏窄时把编辑栏工具栏收一档，保证六个标签和色点都露得出来 */
@media (max-width: 1240px) {
  .editor-head { gap: 8px; }
  .pane-head-left { gap: 7px; }
  .hist-btns button { width: 24px; height: 24px; }
  .quick-insert { gap: 4px; }
  .quick-insert button { height: 28px; min-width: 28px; padding: 0 7px; font-size: 13px; }
  .mini-themes { gap: 6px; margin-left: 8px; padding-left: 10px; }
  .mini-theme { width: 15px; height: 15px; }
}

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; overflow-y: auto; }
  .pane-editor { min-height: 42vh; }
  .pane-preview { min-height: 60vh; }
  .device { max-height: none; }
  .brand-info { display: none; }
  .drawer-body { grid-template-columns: 140px 1fr; }
  .topbar { gap: 10px; padding: 0 10px; }
  .actions .btn.ghost { padding: 8px 10px; }
}

/* ============ 草稿 ============ */
.draft-count {
  display: inline-block;
  min-width: 15px;
  margin-left: 5px;
  padding: 0 4px;
  border-radius: 8px;
  font-size: 11px;
  line-height: 15px;
  text-align: center;
  color: #fff;
  background: var(--primary);
  vertical-align: 1px;
}

.draft-dialog { width: 520px; max-width: 92vw; padding: 24px; }

.draft-list { max-height: 46vh; overflow-y: auto; margin: 6px 0 2px; }

.draft-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  transition: background .14s;
}
.draft-item:hover { background: #f8f6f2; }
.draft-item.active { background: var(--primary-soft); border-color: #ecd9f7; }
.draft-main { flex: 1 1 auto; min-width: 0; }
.draft-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.draft-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.draft-act {
  flex: 0 0 auto;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  color: #8b7aa6;
  background: #f4eafb;
  transition: all .14s;
}
.draft-act:hover { background: var(--primary-soft); color: var(--primary); }
.draft-act.del:hover { background: #fdeceb; color: #c0392b; }
.draft-empty {
  font-size: 13px;
  color: var(--muted);
  padding: 24px 4px;
  text-align: center;
}

/* 迁移备份：换电脑时把本地数据带走 */
.draft-backup {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}
.draft-backup-row { display: flex; gap: 8px; }

/* 必填校验 */
.dlg-err { margin-top: 8px; font-size: 12.5px; color: #c0392b; }
.dlg-input.invalid { border-color: #d9534f; box-shadow: 0 0 0 3px rgba(217, 83, 79, .1); }

/* 预览标题：还没填标题时弱化显示 */
.wx-title.is-empty { color: #191919; font-weight: 700; }

/* 标题输入用的宽版对话框 */
.dialog-wide { width: 440px; max-width: 92vw; }
