/* ============================================================
   Clara BBS — 编辑器样式（前后台共享，单一来源）
   前台 layout.php 与后台帖子编辑页均加载本文件；
   规则自 app.css 抽取（编辑器 + .rich-text 预览排版 + 代码复制按钮），
   两套布局的 :root CSS 变量同名同值，本文件直接引用即可。
   ============================================================ */

/* ---------------- 编辑器 ---------------- */
.editor { border: 1px solid var(--bd); border-radius: 0; background: var(--card); overflow: hidden; }
.editor:focus-within { border-color: var(--ac); box-shadow: 0 0 0 3px rgba(217,119,87,.12); }
.editor-toolbar { display: flex; align-items: center; gap: 2px; padding: 7px 10px; border-bottom: 1px solid var(--soft); background: var(--soft-2); flex-wrap: wrap; }
.ed-btn { border: none; background: none; cursor: pointer; padding: 5px 9px; border-radius: 0; font-size: 13px; color: var(--tx-2); font-family: var(--sans); display: inline-flex; align-items: center; gap: 4px; }
.ed-btn:hover { background: var(--soft); color: var(--tx); }
.ed-sep { width: 1px; height: 16px; background: var(--bd); margin: 0 6px; }
.ed-tip { font-size: 11.5px; color: var(--tx-3); margin-left: auto; }
.editor-area { width: 100%; border: none; outline: none; resize: vertical; min-height: 180px; padding: 14px 16px; font-size: 14.5px; font-family: var(--sans); line-height: 1.8; color: transparent; caret-color: transparent; background: transparent; position: relative; z-index: 1; }
.editor-area::placeholder { color: var(--tx-3); opacity: 1; }
/* 选区底色（文字透明，仅显示色带；必须半透明——不透明色带会盖住下层镜像文字，全选时全部文字"消失"） */
.editor-area::selection { background: rgba(217,119,87,.28); }
/* 镜像层内的自定义光标：原生光标按透明代码文本定位会偏离表情，改由镜像层绘制 */
.ed-caret { display: inline-block; width: 2px; height: 1.4em; background: var(--tx); vertical-align: -0.3em; margin: 0 -1px; animation: edCaretBlink 1.1s steps(1, end) infinite; }
@keyframes edCaretBlink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

/* 镜像层：与 textarea 同字体同内边距，[em] 表情渲染为小图，文字颜色恢复可见 */
.editor-input-wrap { position: relative; background: var(--card); }
.editor-highlight {
  position: absolute; left: 0; top: 0; right: 0; bottom: 0; z-index: 0;
  padding: 14px 16px; font-size: 14.5px; font-family: var(--sans); line-height: 1.8;
  color: var(--tx); white-space: pre-wrap; overflow-wrap: break-word;
  overflow: hidden; pointer-events: none;
}
.editor-highlight img.md-em { height: 25px; width: auto; max-width: 90px; object-fit: contain; vertical-align: -6px; margin: 0 1px; }
/* [img] 上传图片的行内缩略图（与表情同尺寸保两层对齐，加边框与表情区分） */
.editor-highlight img.md-em-img { border: 1px solid var(--bd); border-radius: 0; padding: 1px; box-sizing: border-box; background: var(--card); }
/* 原图查看浮层（编辑区点击 [img] 缩略图触发；全屏居中，点任意处/Esc 关闭） */
.ed-imgview { position: fixed; inset: 0; z-index: 9999; background: rgba(15,14,12,.82); display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 24px; }
.ed-imgview img { max-width: 92vw; max-height: 88vh; border-radius: 0; box-shadow: 0 24px 80px rgba(0,0,0,.5); }
.editor-foot { display: flex; justify-content: flex-end; padding: 8px 10px; border-top: 1px solid var(--soft); background: var(--soft-2); }
.editor-preview { border-top: 1px solid var(--bd); padding: 16px; background: var(--soft-2); max-height: 400px; overflow-y: auto; }
.ed-file { display: none; }

/* 表情按钮锁定态（会员专属时非会员可见） */
.ed-btn.is-locked { color: var(--tx-3); }
/* 表情面板：网格首次展开时由 JS 构建 */
.ed-emoji-panel[hidden] { display: none; }
.ed-emoji-panel { border-bottom: 1px solid var(--soft); background: var(--soft-2); padding: 10px 12px 12px; }
.ed-emoji-locked { margin: 0 0 10px; }
.ed-emoji-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 6px; max-height: 216px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--bd-2) transparent;
}
.ed-emoji-grid::-webkit-scrollbar { width: 6px; }
.ed-emoji-grid::-webkit-scrollbar-track { background: transparent; }
.ed-emoji-grid::-webkit-scrollbar-thumb { background: var(--bd-2); border-radius: 0; }
.ed-emoji-grid::-webkit-scrollbar-thumb:hover { background: var(--tx-3); }
.ed-emoji-grid img {
  width: 100%; height: 64px; object-fit: contain;
  background: var(--card); border: 1px solid var(--bd); border-radius: 0;
  padding: 3px; cursor: pointer; transition: border-color .15s, transform .1s;
}
.ed-emoji-grid img:hover { border-color: var(--ac); transform: translateY(-1px); }
/* 锁定态预览：模糊不可点 */
.ed-emoji-grid.is-locked img { filter: blur(3px) saturate(.8); pointer-events: none; cursor: not-allowed; }
/* 附件上传面板（上传文件 / 网盘链接双模式 + 出售价格 + 下载权限） */
.ed-attach-tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.ed-attach-tab { padding: 5px 12px; border: 1px solid var(--bd-2); border-radius: 0; background: var(--card); color: var(--tx-2); font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; transition: all .15s; }
.ed-attach-tab:hover { border-color: var(--ac); color: var(--tx); }
.ed-attach-tab.is-active { background: var(--ac); border-color: var(--ac); color: #fff; }
.ed-attach-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.ed-attach-form:last-of-type { margin-bottom: 0; }
.ed-attach-form input[type=text], .ed-attach-form input[type=number], .ed-attach-form select { padding: 6px 10px; border: 1px solid var(--bd-2); border-radius: 0; background: var(--card); color: var(--tx); font-size: 12.5px; }
.ed-attach-url { flex: 1; min-width: 200px !important; }
.ed-attach-filename { font-size: 12px; color: var(--tx-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.ed-attach-filename.is-set { color: var(--tx); font-weight: 600; }
.ed-attach-groups { display: flex; align-items: center; gap: 6px 12px; flex-wrap: wrap; padding: 8px 10px; border: 1px dashed var(--bd-2); border-radius: 0; background: var(--soft-2); margin-bottom: 8px; }
.ed-attach-groups-label { font-size: 11.5px; color: var(--tx-3); }
.ed-attach-group { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--tx-2); cursor: pointer; }
.ed-attach-group input { accent-color: var(--ac); }
.ed-attach-cur-static { font-size: 12px; color: var(--tx-3); white-space: nowrap; }
.ed-attach-hint { font-size: 11.5px; color: var(--tx-3); margin: 8px 0 0; line-height: 1.6; word-break: break-all; }
/* 注：锁定面板横幅 .member-locked 是前台隐私设置/会员横幅共用样式，保留在 app.css；
   后台管理员始终豁免锁定，编辑器锁定态在后台不会出现 */

/* ---------------- AI 写作助手面板（与表情/附件面板同层结构） ---------------- */
.ed-ai-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.ed-ai-head strong { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; }
.ed-ai-scope { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--tx-3); }
.ed-ai-scope em { font-style: normal; color: var(--ac-2); }
.ed-ai-modes { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ed-ai-modes .ed-ai-go { margin-left: auto; }
.ed-ai-mode { padding: 5px 12px; border: 1px solid var(--bd-2); border-radius: 0; background: var(--card); color: var(--tx-2); font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; transition: all .15s; }
.ed-ai-mode:hover { border-color: var(--ac); color: var(--tx); }
.ed-ai-mode.is-active { background: var(--ac); border-color: var(--ac); color: #fff; }
.ed-ai-result { margin-top: 10px; border: 1px solid var(--bd-2); border-radius: 0; background: var(--card); padding: 10px 12px; }
.ed-ai-result-text { font-size: 13px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; max-height: 240px; overflow-y: auto; color: var(--tx); }
.ed-ai-result-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.ed-ai-hint { font-size: 11.5px; color: var(--tx-3); margin: 8px 0 0; line-height: 1.6; }
/* 深色主题：AI 按钮激活态绿底配深字（复用主题主色变量，无需额外覆盖） */

/* ---------------- 富文本内容（编辑器预览 + 前台正文排版共用） ---------------- */
.rich-text { word-break: break-word; }
.rich-text p { margin: 0 0 14px; }
.rich-text h2, .rich-text h3, .rich-text h4 { font-family: var(--serif); margin: 26px 0 12px; line-height: 1.5; scroll-margin-top: 90px; }
.rich-text h2 { font-size: 21px; border-bottom: 1px solid var(--soft); padding-bottom: 8px; }
.rich-text h3 { font-size: 17.5px; }
.rich-text h4 { font-size: 15.5px; }
.rich-text blockquote { border-left: 3px solid var(--ac); background: var(--soft-2); margin: 14px 0; padding: 10px 18px; border-radius: 0; color: var(--tx-2); }
.rich-text blockquote p:last-child { margin-bottom: 0; }
/* 代码块：深底浅字（与 toast 同源的暖黑），language 标签为左上角徽标（仅声明了语言的块显示） */
.rich-text pre.code-block {
  background: #27261F; color: #EDEAE0;
  border: 1px solid #3A362C; border-radius: 0;
  padding: 40px 18px 16px; margin: 14px 0;
  font-size: 14px; line-height: 1.75;
  font-family: "SF Mono", Consolas, "Courier New", monospace;
  white-space: pre; word-break: normal; tab-size: 4;
  overflow-x: auto; position: relative;
}
/* 关键修复：重置全局行内 code 样式（浅底+内边距）对代码块的污染，否则浅色文字落在浅色背景上看不清 */
.rich-text pre.code-block code { background: none; padding: 0; border-radius: 0; font-size: inherit; color: inherit; display: block; }
.rich-text pre.code-block[data-lang]::before {
  content: attr(data-lang);
  position: absolute; top: 0; left: 0;
  padding: 5px 12px 4px; font-size: 11px; letter-spacing: .8px;
  color: #A8A48F; text-transform: uppercase;
  font-family: var(--sans);
  background: rgba(250,249,245,.07);
  border-right: 1px solid #3A362C; border-bottom: 1px solid #3A362C;
  border-radius: 0;
}
/* 代码选中高亮（深底上默认选中色几乎不可见） */
.rich-text pre.code-block ::selection { background: rgba(217,119,87,.45); }
/* 复制按钮：默认仅微弱可见，悬停/触摸时清晰呈现，复制成功后变主题色 */
.code-copy-btn {
  position: absolute; top: 8px; right: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0;
  background: rgba(250,249,245,.08); color: #A8A48F;
  border: 1px solid transparent; border-radius: 0;
  cursor: pointer; opacity: 0; transition: all .15s;
}
.rich-text pre.code-block:hover .code-copy-btn,
.code-copy-btn:focus-visible { opacity: 1; }
.code-copy-btn:hover { background: rgba(250,249,245,.16); color: #EDEAE0; }
.code-copy-btn.is-copied { opacity: 1; background: var(--ac); color: #FAF9F5; }
/* 触屏无悬停：常显（半透明，不抢视觉） */
@media (hover: none) {
  .code-copy-btn { opacity: .75; width: 34px; height: 34px; }
}
.rich-text img { border-radius: 0; margin: 8px 0; border: 1px solid var(--bd); max-width: 100%; }
/* 正文表情（[em] 标签）：内联小尺寸，随内容流动 */
.rich-text img.md-em { display: inline-block; vertical-align: middle; height: 64px; width: auto; max-width: 120px; margin: 2px 4px; }
.rich-text hr { border: none; border-top: 1px solid var(--bd); margin: 22px 0; }
.rich-text a.img-link img, .rich-text p > img { display: block; max-width: 100%; }
.rich-text strong { color: var(--tx); }

/* ---------------- 响应式（与 app.css 断点一致） ---------------- */
@media (max-width: 768px) {
  .editor-area { min-height: 140px; }
  .ed-tip { display: none; }
  /* 代码块小屏：字号与内边距收紧，横向滚动查看长行 */
  .rich-text pre.code-block { font-size: 13px; padding: 36px 12px 12px; line-height: 1.7; }
}

/* ---------------- 打印 ---------------- */
@media print {
  /* 代码块打印：深底改为白底黑字细边框（浏览器默认不打印背景色，需显式覆盖文字颜色） */
  .rich-text pre.code-block { background: #fff; color: #191817; border-color: #DDD9CB; padding: 12px 14px; }
  .rich-text pre.code-block[data-lang]::before { color: #8A8672; background: none; border-color: #DDD9CB; }
}

/* ---------------- 帖子编辑/发布页共用区块（前台 app.css 与后台编辑页均经本文件加载） ---------------- */
/* 附件扩展名徽章（前台附件卡片 + 前后台编辑页附件设置区共用） */
.attach-ext { flex: 0 0 auto; background: var(--card); border: 1px solid var(--bd-2); border-radius: 0; padding: 5px 9px; font-size: 11px; font-weight: 700; color: var(--tx-3); letter-spacing: .5px; }
.attach-ext.is-link { display: inline-flex; align-items: center; justify-content: center; padding: 4px 7px; color: var(--ac-2); border-color: var(--ac-soft); }
/* 编辑页附件设置区 */
.field-attach-edit { border: 1px dashed var(--bd); border-radius: 0; padding: 12px 16px; margin-bottom: 16px; }
.field-attach-head { font-size: 13.5px; font-weight: 600; color: var(--tx-2); display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.attach-edit-item { border: 1px solid var(--bd); border-radius: 0; background: var(--soft-2); padding: 12px 14px; }
.attach-edit-item + .attach-edit-item { margin-top: 10px; }
.attach-edit-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.attach-edit-title strong { font-size: 13.5px; word-break: break-all; }
.attach-edit-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.attach-edit-form input[type=text], .attach-edit-form input[type=number], .attach-edit-form select { padding: 6px 10px; border: 1px solid var(--bd-2); border-radius: 0; background: var(--card); color: var(--tx); font-size: 12.5px; }
.attach-edit-form .ae-name { width: 160px; }
.attach-edit-form .ae-url { flex: 1; min-width: 200px; }
.attach-edit-groups { display: flex; align-items: center; gap: 6px 12px; flex-wrap: wrap; width: 100%; padding: 8px 10px; border: 1px dashed var(--bd-2); border-radius: 0; background: var(--card); }
/* 发布/编辑页投票折叠区 */
.field-poll { border: 1px dashed var(--bd); border-radius: 0; padding: 12px 16px; margin-bottom: 16px; }
.field-poll > summary { cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--tx-2); user-select: none; }
.field-poll[open] > summary { margin-bottom: 8px; }
