/* ============================================================================
 * 玲君永恒 · 图文正文样式（v3.28）
 * 同时服务两种形态：
 *   1) 编辑态 .re-*                    —— 后台/弹层里的所见即所得编辑器
 *   2) 只读态 .rich-p / .rich-fig       —— 文章页、条目页的正文展示
 * 配色沿用全站变量（css/style.css :root），后台场景有回退色值。
 * ========================================================================== */

/* ---------------- 编辑态 ---------------- */
.re {
  border: 1px solid var(--line, #e6ded2);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.re-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 10px;
  background: #faf7f2;
  border-bottom: 1px solid var(--line, #f0e8dc);
}

.re-add {
  font: inherit;
  font-size: 13px;
  line-height: 1;
  padding: 7px 12px;
  border: 1px solid #d9cbb6;
  border-radius: 6px;
  background: #fff;
  color: #5b4636;
  cursor: pointer;
  white-space: nowrap;
}
.re-add:hover { background: #f3ece1; }
.re-add:disabled { opacity: .5; cursor: not-allowed; }

.re-count {
  font-size: 12px;
  color: #9a8b7d;
  white-space: nowrap;
}
.re-count.over { color: #b34a3c; }

.re-msg {
  font-size: 12px;
  color: #a0563c;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.re-body {
  min-height: 132px;
  max-height: 52vh;
  overflow-y: auto;
  padding: 12px 14px;
  font-size: 15px;
  line-height: 1.95;
  color: var(--text, #3a322b);
  outline: none;
  word-break: break-word;
  -webkit-overflow-scrolling: touch;
}
.re-body:focus { background: #fffdfa; }
/* v3.39：键盘可见焦点。
   正文编辑区原来只改背景色（.re-body:focus），键盘用户看不出焦点在哪。
   这里用 :focus-visible 补一圈轮廓——只在键盘操作时出现，鼠标点击不打扰。 */
.re-body:focus-visible {
  outline: 2px solid var(--theme, #5b4636);
  outline-offset: -2px;   /* 往内描，避免被 .re 的 overflow:hidden 裁掉 */
}
/* 工具条上的按钮（插入图片 / 导入 Word）也要有焦点态 */
.re-add:focus-visible,
.re-fig-btn:focus-visible {
  outline: 2px solid var(--theme, #5b4636);
  outline-offset: 2px;
}
.re-body p { margin: 0 0 10px; }
.re-body p:last-child { margin-bottom: 0; }
/* 空态提示 */
.re-body.is-empty::before {
  content: attr(data-ph);
  display: block;
  color: #b9ab9b;
  pointer-events: none;
}

/* 编辑态图片块 */
.re-fig {
  position: relative;
  margin: 12px 0;
  padding: 0;
  border-radius: 8px;
  overflow: hidden;
  background: #f4efe7;
  line-height: 0;
}
.re-fig img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 420px;
  object-fit: contain;
  background: #f4efe7;
}
.re-fig figcaption {
  line-height: 1.6;
  font-size: 12px;
  color: #8a7c6d;
  padding: 6px 10px 8px;
  background: #faf7f2;
  word-break: break-all;
}

.re-fig-tools {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: .92;
}
.re-fig-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: rgba(0, 0, 0, .52);
  color: #fff;
  font-size: 15px;
  line-height: 30px;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.re-fig-btn:hover { background: rgba(0, 0, 0, .72); }
.re-fig-btn[data-act="del"]:hover { background: #b34a3c; }

.re-file { display: none; }

/* ---------------- 只读态（正文展示） ---------------- */
.rich-p {
  margin: 0 0 12px;
  font-size: inherit;
  line-height: inherit;
  color: inherit;
  white-space: pre-wrap;
  word-break: break-word;
}
.rich-p:last-child { margin-bottom: 0; }

.rich-fig {
  margin: 18px 0;
  padding: 0;
}
.rich-fig img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 78vh;
  object-fit: contain;
  border-radius: 8px;
  background: #f4efe7;
}
.rich-fig figcaption {
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-soft, #8a7c6d);
  text-align: center;
  word-break: break-all;
}

/* ---------------- 首页亲友文章列表内嵌（限高，避免单条过长） ---------------- */
.msg-inline-text .rich-p { margin-bottom: 8px; line-height: 1.85; }
.msg-inline-text .rich-fig { margin: 10px 0; }
.msg-inline-text .rich-fig img { max-height: 260px; border-radius: 6px; }
.msg-inline-text .rich-fig figcaption { text-align: left; }

/* ---------------- 宿主容器（各页面放置编辑器的位置） ---------------- */
.rich-host {
  display: block;
  width: 100%;
  box-sizing: border-box;
}
/* 条目页：原 textarea 的 padding/border 交给 .re 自己管，避免双层内边距 */
.fi-text-edit.re {
  padding: 0;
  border: 0;
  margin-top: 26px;
  overflow: visible;
}
.fi-text-edit.re .re-body { border-radius: 0 0 8px 8px; }
/* 后台文章表单 / 首页弹层：与外层输入框保持一致的间距 */
.adm-panel .rich-host { margin: 0 0 10px; }
.message-form .rich-host { margin-bottom: 10px; }

/* ---------------- 窄屏 ---------------- */
@media (max-width: 640px) {
  .re-body {
    /* 16px 防 iOS 聚焦缩放（全站铁律） */
    font-size: 16px;
    min-height: 120px;
    max-height: 46vh;
    padding: 10px 12px;
  }
  .re-add { font-size: 14px; padding: 9px 14px; }
  .re-fig-btn { width: 34px; height: 34px; line-height: 34px; font-size: 16px; }
  .rich-fig { margin: 14px 0; }
  .rich-fig figcaption { font-size: 12px; }
}
