/* ==========================================================
 * style.css —— 工作台界面样式（与预览内容完全隔离）
 * 预览区内的所有样式都来自 render.js 生成的内联 style
 * ========================================================== */

:root {
  --bg: #f5f4f1;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --border: #e6e3dd;
  --border-soft: #efece7;
  --text: #2f3a44;
  --text-2: #7d8791;
  --text-3: #a8adb2;
  --accent: #7d8c85;
  --accent-soft: #eef2f0;
  --accent-line: #bfc8c3;
  --danger: #c0796a;
  --danger-soft: #fcf1f0;
  --warn: #c8a061;
  --warn-soft: #fdf7ee;
  --ok: #6b9078;
  --ok-soft: #f0f6f2;
  --radius: 8px;
  --mono: Menlo, Consolas, "Courier New", "Microsoft YaHei", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body[data-ui="dark"] {
  --bg: #171a1d;
  --surface: #202428;
  --surface-2: #1c2024;
  --border: #32383e;
  --border-soft: #282d33;
  --text: #d9dee4;
  --text-2: #8b949a;
  --text-3: #6b747c;
  --accent: #8fa69e;
  --accent-soft: #2a322f;
  --accent-line: #4a5651;
  --danger: #cf8b7c;
  --danger-soft: #332623;
  --warn: #c8a061;
  --warn-soft: #332b1f;
  --ok: #7fa88c;
  --ok-soft: #243029;
}

* { box-sizing: border-box; }

html, body {
  height: 100%; margin: 0; padding: 0;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6, p, ul, ol, pre, figure, blockquote { margin: 0; padding: 0; }
button, select, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* ---------- 布局 ---------- */
.app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.topbar {
  flex: 0 0 54px;
  display: flex; align-items: center; gap: 16px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 9px; flex: 0 0 auto; }
.brand-mark {
  width: 18px; height: 18px; border-radius: 5px;
  background: var(--accent);
  position: relative;
}
.brand-mark::after {
  content: ''; position: absolute; left: 4px; top: 5px;
  width: 10px; height: 1.5px; background: var(--surface);
  box-shadow: 0 3px 0 var(--surface), 0 6px 0 var(--surface);
}
.brand-name { font-size: 14px; font-weight: 600; letter-spacing: .3px; }

.topbar-tools { display: flex; align-items: center; gap: 10px; flex: 1; }
.spacer { flex: 1; }

.field { display: flex; align-items: center; gap: 6px; }
.field-label { font-size: 12px; color: var(--text-2); }
.field select {
  height: 30px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-2); cursor: pointer;
  outline: none;
}
.field select:focus { border-color: var(--accent-line); }

.btn {
  height: 30px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); cursor: pointer;
  font-size: 13px; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--accent-line); }
.btn:active { transform: translateY(.5px); }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500;
}
.btn-primary:hover { background: var(--accent); opacity: .88; }
.btn-icon { width: 30px; padding: 0; text-align: center; }

.workspace { flex: 1; display: flex; min-height: 0; }

.panel { display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.panel-left { flex: 0 0 208px; border-right: 1px solid var(--border); }
.panel-editor { flex: 1 1 auto; min-width: 260px; }
.panel-preview { flex: 0 0 428px; border-left: 1px solid var(--border); background: var(--bg); }

.panel-head {
  flex: 0 0 38px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 14px;
  font-size: 12px; color: var(--text-2);
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
}
.panel-hint { font-size: 11px; color: var(--text-3); }

/* ---------- 左：元素库 ---------- */
.panel-body { flex: 1; overflow-y: auto; padding-bottom: 20px; }

.group-title {
  padding: 14px 14px 7px;
  font-size: 11px; color: var(--text-3); letter-spacing: .6px;
}
.el-btn {
  display: block; width: calc(100% - 24px);
  margin: 0 12px 6px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); text-align: left; cursor: pointer;
  font-size: 13px; line-height: 1.3;
  transition: background .15s, border-color .15s;
}
.el-btn:hover { background: var(--accent-soft); border-color: var(--accent-line); }
.el-btn small { display: block; margin-top: 2px; font-size: 11px; color: var(--text-3); }

.deco-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 6px; padding: 0 12px 10px;
}
.deco-btn {
  height: 42px; padding: 4px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  transition: background .15s, border-color .15s;
}
.deco-btn:hover { background: var(--accent-soft); border-color: var(--accent-line); }
.deco-btn svg { max-width: 100%; max-height: 100%; }

/* 分组下方的一行说明（比 group-title 更靠内容一点） */
.group-hint { display: block; padding: 0 14px 7px; line-height: 1.55; }
.group-hint code {
  padding: 1px 4px; border-radius: 3px;
  background: var(--accent-soft); color: var(--text-2);
  font-size: 10.5px; word-break: break-all;
}

/* 装饰元素的「插入方式」切换 */
.deco-mode-row { display: flex; align-items: center; gap: 6px; padding: 0 12px 8px; flex-wrap: wrap; }
.deco-mode-row select {
  padding: 3px 6px; font-size: 11px;
  border: 1px solid var(--border); border-radius: 5px;
  background: var(--surface); color: var(--text-1); cursor: pointer;
}
.deco-mode-tip { flex: 1 1 100%; font-size: 10.5px; color: var(--text-3); }
.deco-mode-tip code { background: var(--accent-soft); }

/* 设置面板里的尺寸滑杆行 */
.deco-size-row { flex-wrap: wrap; gap: 14px; }
.deco-size-row .slider input[type=range] { width: 96px; }

/* ---------- 自定义主题管理 + 序号配色方案 ---------- */
.theme-mgr-row { flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.theme-mgr-row .txt { min-width: 150px; }

.palette-colors { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0 10px; }
.palette-swatch {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 6px 4px 4px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface);
}
.palette-swatch input[type=color] {
  width: 28px; height: 24px; padding: 0;
  border: none; background: none; cursor: pointer;
}
.palette-swatch .pl-idx { font-size: 10.5px; color: var(--text-3); min-width: 12px; }
.palette-swatch .pl-hex { width: 64px; flex: none; }
.palette-swatch button {
  border: none; background: none; cursor: pointer;
  color: var(--text-3); font-size: 14px; line-height: 1; padding: 0 2px;
}
.palette-swatch button:hover { color: #c0392b; }
.palette-chip {
  display: inline-block; width: 18px; height: 18px;
  border-radius: 5px; border: 1px solid rgba(0,0,0,.08); vertical-align: middle;
}
.palette-readonly { font-size: 11px; color: var(--text-3); padding: 0 0 10px; }

/* ---------- 中：编辑器 ---------- */
#editor {
  flex: 1; width: 100%;
  padding: 16px 18px;
  border: none; outline: none; resize: none;
  background: var(--surface-2);
  font-family: var(--mono); font-size: 13px; line-height: 1.85;
  color: var(--text);
  tab-size: 2;
}
#editor::placeholder { color: var(--text-3); }

.editor-foot {
  flex: 0 0 30px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px;
  font-size: 11px; color: var(--text-3);
  border-top: 1px solid var(--border-soft);
  background: var(--surface);
}
.dot { color: var(--border); }

/* ---------- 右：预览 ---------- */
.preview-scroll { flex: 1; overflow-y: auto; padding: 20px 0 30px; }

.phone {
  width: 375px; margin: 0 auto;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 0 0 26px;
  position: relative;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .04);
}
.phone-notch {
  width: 108px; height: 18px;
  margin: 8px auto 4px;
  background: var(--surface-2);
  border-radius: 10px;
}
body[data-ui="dark"] .phone-notch { background: #2a2f34; }

.phone-screen { padding: 0 18px; }
.phone-title {
  font-size: 20px; font-weight: 700; color: #1f2429; line-height: 1.4;
  margin: 10px 0 8px;
}
.phone-meta { font-size: 12px; color: #9aa1a6; margin-bottom: 18px; }
.phone-body { min-height: 120px; }

/* ---------- 体检面板 ---------- */
.check-head {
  flex: 0 0 36px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer; user-select: none;
}
.check-title { font-size: 12px; color: var(--text-2); }
.check-badge {
  padding: 1px 7px; border-radius: 9px;
  font-size: 11px; background: var(--border-soft); color: var(--text-2);
}
.check-badge.ok { background: var(--ok-soft); color: var(--ok); }
.check-badge.warn { background: var(--warn-soft); color: var(--warn); }
.check-badge.error { background: var(--danger-soft); color: var(--danger); }
.check-toggle { margin-left: auto; font-size: 11px; color: var(--text-3); }

.check-body {
  flex: 0 0 auto; max-height: 216px; overflow-y: auto;
  padding: 10px 12px;
  background: var(--surface-2);
  border-top: 1px solid var(--border-soft);
  display: none;
}
.check-body.open { display: block; }

.check-item {
  padding: 8px 10px; margin-bottom: 6px;
  border-radius: 6px; font-size: 12px; line-height: 1.6;
  background: var(--surface);
  border-left: 2px solid var(--border);
}
.check-item.error { background: var(--danger-soft); border-left-color: var(--danger); }
.check-item.warn { background: var(--warn-soft); border-left-color: var(--warn); }
.check-item .ci-msg { color: var(--text); }
.check-item .ci-top { display: flex; align-items: flex-start; gap: 8px; }
.check-item .ci-top .ci-msg { flex: 1; }
.check-item .ci-where { display: block; margin-top: 3px; font-size: 11px; color: var(--text-3); }
.check-item .ci-loc {
  flex: none; padding: 2px 8px; border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); color: var(--accent); font-size: 11px; line-height: 1.6;
  cursor: pointer; white-space: nowrap; font-family: inherit;
}
.check-item .ci-loc:hover { border-color: var(--accent); background: var(--accent-soft); }
.check-item .ci-loc.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.check-item .ci-fix { display: block; margin-top: 3px; color: var(--text-2); font-size: 11px; }

/* ---------- 体检定位：预览区高亮（仅界面视觉，复制时会剥离标记） ---------- */
#preview [data-hl] {
  outline: 2px dashed var(--danger); outline-offset: 2px; border-radius: 2px;
}
#preview [data-hl-cur] {
  outline: 2px solid var(--danger);
  background: rgba(192, 121, 106, .10);
  animation: hlPulse 1s ease-in-out 3;
  transition: background .3s;
}
@keyframes hlPulse {
  0%, 100% { background: rgba(192, 121, 106, .06); }
  50% { background: rgba(192, 121, 106, .20); }
}
.check-item .ci-sample {
  display: block; margin-top: 4px; padding: 3px 6px;
  background: rgba(0, 0, 0, .04); border-radius: 3px;
  font-family: var(--mono); font-size: 11px; color: var(--text-3);
  word-break: break-all;
}
body[data-ui="dark"] .check-item .ci-sample { background: rgba(255, 255, 255, .05); }

.check-empty { padding: 6px 2px; font-size: 12px; color: var(--ok); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 40px;
  transform: translateX(-50%) translateY(10px);
  padding: 9px 18px; border-radius: 8px;
  background: #2f3a44; color: #fff; font-size: 13px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 99;
}
body[data-ui="dark"] .toast { background: #3a4149; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 设置弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: none; }
.modal.open { display: block; }
.modal-mask { position: absolute; inset: 0; background: rgba(20, 24, 28, .42); }
.modal-box {
  position: relative;
  width: 620px; max-width: calc(100vw - 40px);
  max-height: calc(100vh - 80px);
  margin: 40px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-head {
  flex: 0 0 46px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  font-size: 14px; font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.modal-close {
  width: 26px; height: 26px; line-height: 22px;
  border: none; background: transparent; cursor: pointer;
  font-size: 20px; color: var(--text-2); border-radius: 5px;
}
.modal-close:hover { background: var(--border-soft); color: var(--text); }
.modal-body { flex: 1; overflow-y: auto; padding: 4px 18px 22px; }

.mset { padding: 16px 0; border-bottom: 1px solid var(--border-soft); }
.mset:last-child { border-bottom: none; }
.mset-title { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.mset-desc { font-size: 12px; color: var(--text-2); line-height: 1.7; margin-bottom: 12px; }
.mset-desc code {
  padding: 1px 4px; border-radius: 3px;
  background: var(--border-soft); font-family: var(--mono); font-size: 11px;
}
.mset-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.mset-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.mset-err { flex: 1; font-size: 12px; color: var(--danger); }
.mset-err.info { color: var(--text-2); }
#decoTpl.drop-hover { border-color: var(--accent-line); border-style: dashed; background: var(--accent-soft); }
.mset-tip { margin-top: 10px; font-size: 11px; color: var(--text-3); }

.txt {
  height: 30px; padding: 0 10px; flex: 1; min-width: 180px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-2); outline: none;
}
.txt:focus { border-color: var(--accent-line); }
.txt.area {
  width: 100%; height: 96px; padding: 8px 10px; resize: vertical;
  font-family: var(--mono); font-size: 12px; line-height: 1.6;
}

.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 14px; }
.sw { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.sw-pick {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 11px; color: var(--text-2); cursor: pointer;
}
.sw input[type=color] {
  width: 100%; height: 32px; padding: 0;
  border: 1px solid var(--border); border-radius: 6px;
  background: none; cursor: pointer;
}
/* 色值文本框：实时显示 #rrggbb，点击全选即可复制，也可直接粘贴改色 */
.hex-in {
  width: 100%; min-width: 0; box-sizing: border-box;
  font-family: var(--mono); font-size: 10.5px; line-height: 1.5;
  letter-spacing: .2px; text-align: center;
  color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 2px 3px; outline: none;
  transition: border-color .12s, color .12s;
}
.hex-in:hover { border-color: var(--accent-line); color: var(--text); }
.hex-in:focus { border-color: var(--accent); color: var(--text); background: var(--surface); }
.slider { display: flex; align-items: center; gap: 8px; }
.slider input[type=range] { width: 120px; accent-color: var(--accent); }
.slider-val { font-size: 12px; color: var(--text-2); min-width: 30px; }

.deco-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.deco-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 4px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-2); font-size: 11px; color: var(--text-2);
  cursor: pointer;
}
.deco-chip:hover { border-color: var(--accent-line); color: var(--text); }
.dc-text { display: flex; flex-direction: column; line-height: 1.3; }
.dc-text i {
  font-style: normal; font-size: 10px; color: var(--text-3);
  font-family: var(--mono);
}
.demo-row { align-items: center; gap: 6px; margin-bottom: 10px; }
.deco-chip .dc-preview {
  width: 30px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border-radius: 4px; overflow: hidden;
}
.deco-chip .dc-preview svg { max-width: 100%; max-height: 100%; }
.deco-chip button {
  border: none; background: none; cursor: pointer;
  color: var(--text-3); font-size: 14px; padding: 0 2px;
}
.deco-chip button:hover { color: var(--danger); }

/* ---------- 草稿箱 ---------- */
.modal-box-sm { width: 520px; }
.draft-list { margin-top: 12px; }
.draft-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2);
}
.draft-item.current { border-color: var(--accent-line); background: var(--accent-soft); }
.di-main { flex: 1; min-width: 0; cursor: pointer; }
.di-main b {
  display: block; font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.di-main small { display: block; margin-top: 2px; font-size: 11px; color: var(--text-3); }
.di-ops { display: flex; gap: 6px; }
.di-ops button {
  height: 24px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: 5px;
  background: var(--surface); cursor: pointer;
  font-size: 11px; color: var(--text-2);
}
.di-ops button:hover { color: var(--text); border-color: var(--accent-line); }
.di-ops button[data-del]:hover { color: var(--danger); border-color: var(--danger); }
.draft-empty { padding: 20px 0; text-align: center; font-size: 12px; color: var(--text-3); }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-line); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 窄屏适配 ---------- */
@media (max-width: 1180px) {
  .panel-left { flex-basis: 176px; }
  .panel-preview { flex-basis: 380px; }
  .phone { width: 340px; }
}
