/* =========================================================
   富文本编辑器样式
   ---------------------------------------------------------
   说明：工具栏使用 flex-wrap，窄屏时换行而不是隐藏按钮，
        保证所有功能在任何设备上都可见可点。
   ========================================================= */

.rte {
  --rte-line:   #ddd5c6;
  --rte-ink:    #2f2b26;
  --rte-soft:   #6b6357;
  --rte-faint:  #a49b8c;
  --rte-accent: #8c5b3f;
  --rte-bg:     #fffefb;
  --rte-bar:    #faf7f0;

  border: 1px solid var(--rte-line);
  border-radius: 4px;
  background: var(--rte-bg);
  /* 与全站一致：正文用无衬线，长文写作/阅读更省眼 */
  font-family: var(--font-body, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif);
}

/* ---------- 工具栏 ---------- */
.rte-toolbar {
  display: flex;
  flex-wrap: wrap;              /* 关键：换行，绝不隐藏 */
  align-items: center;
  gap: 2px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--rte-line);
  background: var(--rte-bar);
  border-radius: 4px 4px 0 0;
  position: sticky;
  top: 0;
  z-index: 20;
}

.rte-sep {
  width: 1px;
  height: 20px;
  margin: 0 5px;
  background: var(--rte-line);
  flex: none;
}

.rte-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: #4a443c;
  cursor: pointer;
  flex: none;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.rte-btn svg { width: 16px; height: 16px; display: block; }

.rte-btn:hover {
  background: #f0ebe0;
  border-color: var(--rte-line);
}

.rte-btn.is-active {
  background: #ede4d5;
  border-color: #cdbfa6;
  color: var(--rte-accent);
}

.rte-btn:focus-visible {
  outline: 2px solid var(--rte-accent);
  outline-offset: 1px;
}

/* 字形按钮 B I U S x² x₂ */
.rte-t {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 14px;
  line-height: 1;
}
.rte-t-b { font-weight: 700; }
.rte-t-i { font-style: italic; }
.rte-t-u { text-decoration: underline; }
.rte-t-s { text-decoration: line-through; }
.rte-t sup, .rte-t sub { font-size: 9px; }

/* 下拉选择 */
.rte-select {
  height: 30px;
  max-width: 118px;
  font-family: inherit;
  font-size: 13px;
  color: #4a443c;
  background: #fff;
  border: 1px solid var(--rte-line);
  border-radius: 3px;
  padding: 0 4px;
  cursor: pointer;
  flex: none;
}
.rte-select-wide { max-width: 150px; }
.rte-select:focus { outline: none; border-color: var(--rte-accent); }

/* 颜色按钮 */
.rte-colorwrap {
  position: relative;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  flex: none;
}
.rte-colorwrap:hover { background: #f0ebe0; border-color: var(--rte-line); }

.rte-color-swatch {
  font-family: Georgia, serif;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  color: #4a443c;
  border-bottom: 3px solid #2f2b26;
  padding-bottom: 1px;
  pointer-events: none;
}

.rte-color {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  padding: 0;
  cursor: pointer;
}

/* ---------- 编辑区 ---------- */
.rte-body {
  min-height: 320px;
  max-height: 70vh;
  overflow-y: auto;
  padding: 26px 30px;
  font-family: var(--font-body, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif);
  font-size: 16.5px;
  line-height: 1.95;
  color: var(--rte-ink);
  background: var(--rte-bg);
  outline: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.rte-body:empty::before,
.rte-body:has(> br:only-child)::before {
  content: attr(data-placeholder);
  color: var(--rte-faint);
  pointer-events: none;
}

/* 正文内元素排版 */
.rte-body p { margin: 0 0 1em; }
.rte-body h1 { font-size: 1.7em; margin: 1.2em 0 .6em; line-height: 1.4; }
.rte-body h2 { font-size: 1.42em; margin: 1.2em 0 .6em; line-height: 1.4; }
.rte-body h3 { font-size: 1.2em;  margin: 1.1em 0 .5em; line-height: 1.4; }
.rte-body h4 { font-size: 1.06em; margin: 1em 0 .5em; }

.rte-body ul, .rte-body ol { margin: 0 0 1em; padding-left: 2em; }
.rte-body li { margin: .3em 0; }
.rte-body ul ul, .rte-body ol ol,
.rte-body ul ol, .rte-body ol ul { margin-bottom: 0; }

.rte-body blockquote {
  margin: 1em 0;
  padding: .4em 0 .4em 1.1em;
  border-left: 3px solid var(--rte-accent);
  background: #faf6ee;
  color: #57503f;
}

.rte-body pre {
  margin: 1em 0;
  padding: 14px 16px;
  background: #f4f1e8;
  border: 1px solid var(--rte-line);
  border-radius: 3px;
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 13.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-x: auto;
}

.rte-body code {
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: .92em;
  background: #f4f1e8;
  padding: 1px 5px;
  border-radius: 3px;
}

.rte-body a { color: var(--rte-accent); text-decoration: underline; }

.rte-body img {
  max-width: 100%;
  height: auto;
  border-radius: 3px;
  margin: .4em 0;
}

.rte-body hr {
  border: none;
  border-top: 1px solid var(--rte-line);
  margin: 1.6em 0;
}

.rte-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: .96em;
}
.rte-body th, .rte-body td {
  border: 1px solid var(--rte-line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.rte-body th { background: #f4f0e6; font-weight: 600; }

.rte-body figure { margin: 1em 0; }
.rte-body figcaption {
  font-size: .86em;
  color: var(--rte-soft);
  text-align: center;
  margin-top: .4em;
}

/* ---------- 状态栏 ---------- */
.rte-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 7px 14px;
  border-top: 1px solid var(--rte-line);
  background: var(--rte-bar);
  border-radius: 0 0 4px 4px;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 12px;
  color: var(--rte-faint);
}
.rte-status-words { flex: none; }
.rte-status-hint {
  text-align: right;
  color: #6a8a6f;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 全屏 ---------- */
.rte.rte-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9000;
  border-radius: 0;
  border: none;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 60px rgba(60, 50, 35, .28);
}
.rte.rte-fullscreen .rte-body {
  flex: 1;
  max-height: none;
  padding: 40px max(30px, calc(50vw - 340px));
}
.rte.rte-fullscreen .rte-toolbar { border-radius: 0; }
.rte.rte-fullscreen .rte-status { border-radius: 0; }
body.rte-locked { overflow: hidden; }

/* ---------- 下拉菜单 ---------- */
.rte-menu {
  position: absolute;
  z-index: 9500;
  min-width: 172px;
  padding: 6px;
  background: #fffdf8;
  border: 1px solid var(--rte-line);
  border-radius: 4px;
  box-shadow: 0 10px 30px rgba(70, 55, 35, .16);
}
.rte-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: none;
  border-radius: 3px;
  background: transparent;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 13px;
  color: #4a443c;
  cursor: pointer;
}
.rte-menu-item:hover { background: #f2ece1; color: var(--rte-accent); }

/* ---------- 弹窗 ---------- */
.rte-overlay {
  position: fixed;
  inset: 0;
  z-index: 9600;
  background: rgba(48, 42, 34, .38);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.rte-dialog {
  width: 100%;
  max-width: 440px;
  max-height: 88vh;
  overflow-y: auto;
  background: #fffdf8;
  border: 1px solid var(--rte-line);
  border-radius: 5px;
  box-shadow: 0 24px 60px rgba(50, 40, 25, .3);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
.rte-dialog-title {
  margin: 0;
  padding: 18px 22px 14px;
  font-family: Georgia, "Songti SC", SimSun, serif;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--rte-line);
}
.rte-dialog-body { padding: 18px 22px 6px; }

.rte-field { margin-bottom: 15px; }
.rte-field label {
  display: block;
  font-size: 13px;
  color: var(--rte-soft);
  margin-bottom: 6px;
}
.rte-field input[type="text"],
.rte-field input[type="number"],
.rte-field input[type="url"],
.rte-field textarea,
.rte-field select {
  width: 100%;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 14px;
  color: var(--rte-ink);
  background: #fff;
  border: 1px solid var(--rte-line);
  border-radius: 3px;
}
.rte-field input:focus, .rte-field textarea:focus, .rte-field select:focus {
  outline: none;
  border-color: var(--rte-accent);
  box-shadow: 0 0 0 3px rgba(140, 91, 63, .1);
}
.rte-field input[type="file"] {
  width: 100%;
  font-size: 13px;
  color: var(--rte-soft);
}
.rte-check {
  display: flex !important;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--rte-soft);
  cursor: pointer;
}
.rte-check input { width: auto; }

.rte-dialog-hint {
  font-size: 12.5px;
  color: var(--rte-faint);
  line-height: 1.7;
  margin: 0 0 12px;
}
.rte-hint-error { color: #b04a3a; }

.rte-dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--rte-line);
}
.rte-btn-text {
  padding: 8px 18px;
  font-family: inherit;
  font-size: 13.5px;
  border: 1px solid var(--rte-line);
  border-radius: 3px;
  background: transparent;
  color: var(--rte-soft);
  cursor: pointer;
}
.rte-btn-text:hover { border-color: var(--rte-soft); color: var(--rte-ink); }
.rte-btn-primary {
  background: var(--rte-accent);
  border-color: var(--rte-accent);
  color: #fdfaf4;
}
.rte-btn-primary:hover { background: #7a4d34; color: #fdfaf4; }

/* ---------- 窄屏：只调整尺寸，不减少按钮 ---------- */
@media (max-width: 720px) {
  .rte-toolbar { padding: 6px; gap: 1px; }
  .rte-sep { margin: 0 3px; }
  .rte-btn { width: 28px; height: 28px; }
  .rte-select { max-width: 96px; font-size: 12px; }
  .rte-body { padding: 18px 16px; font-size: 15.5px; }
}
