/* =====================================================================
   蝉脉 · 功能子页内嵌历史（fhist.css）
   ---------------------------------------------------------------------
   2026-09-21 改版：**历史从"页面里的折叠卡"改成"顶部页签的第二页"**
     用户指令：「所有的生成历史都应该以红框里的生成历史为标准，去掉蓝框的生成历史卡，
               全站每个功能的生成历史，全按照绘画MAX红格子里这种生成历史的方式去改」
     即：每个功能子页顶部给一排**页签**（<功能名> / 生成历史），点「生成历史」就是
     整页的历史列表 —— 视觉与「绘画MAX」的生成历史页一致。
     原型：public/paintmax.css 的 .pm-tabs / .pm-hist-*（本文件按它逐条对齐数值）。

   独立文件：不覆盖任何既有样式，全部类名以 .cmfhist / .cmfh 前缀隔离。
   配色取自 style.css 的 :root（品牌橙 --primary: #f95901），不换品牌色。
   ===================================================================== */

/* ---------- 顶部页签（与绘画MAX 的 .pm-tabs 同形） ---------- */
.cmfhist-tabs {
  position: relative;
  display: flex; gap: 4px;
  padding: 4px;
  margin: 10px 0 12px;
  border-radius: 14px;
  background: #f2ece5;                    /* 站内暖灰底，胶囊内嵌感 */
}
.cmfhist-tab {
  flex: 1 1 0; min-width: 0;
  padding: 10px 4px;
  border: 0; border-radius: 11px;
  background: transparent;
  font-family: inherit;
  font-size: 13.5px; font-weight: 700; color: var(--text2, #7a6a5c);
  cursor: pointer;
  transition: background .16s, color .16s, box-shadow .16s;
  -webkit-tap-highlight-color: transparent; -webkit-appearance: none; appearance: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cmfhist-tab.on {
  background: #fff;
  color: var(--primary, #f95901);
  box-shadow: 0 2px 8px rgba(120, 80, 40, .12);
}
.cmfhist-tab:focus-visible { outline: 2px solid rgba(249, 89, 1, .45); outline-offset: 2px; }
.cmfhist-tab-ico { margin-right: 3px; display: inline-flex; vertical-align: -2px; }
.cmfhist-tab-tx { display: inline-block; max-width: 100%; vertical-align: middle; }
.cmfhist-tab-ico svg { width: 14px; height: 14px; display: block; }

/* ---------- 两个"页"的切换：不动 DOM，只用 CSS 显隐 ----------
   🔴 这里刻意用「链式 :not()」而不是给兄弟节点打标记：
      功能页的内容是别人写的、可能**在打开后还会动态追加**节点，
      打标记只能在切换那一刻打一次，后追加的就漏了；
      链式 :not() 由 CSS 每次重算，后加的子节点自动一起被藏起来。
      （:not(a):not(b) 这种简单选择器链在全部现代浏览器都支持） */
.subpanel > .cmfhist { display: none; }                       /* 历史是"第二页"，默认收起 */
.subpanel[data-cmfh-view="hist"] > .cmfhist { display: block; }
.subpanel[data-cmfh-view="hist"] > :not(.sub-topbar):not(.cmfhist-tabs):not(.cmfhist) {
  display: none !important;                                   /* 功能页整块藏起来 */
}
.cmfhist[hidden] { display: none !important; }                 /* 兜底（防被 display:flex/grid 盖掉） */

/* ---------- 历史页 ---------- */
.cmfhist {
  min-width: 0;                 /* 极端窄容器下不撑宽父级 */
  grid-column: 1 / -1;          /* ≥1024px 时父级可能是两列 grid → 本区整行通栏 */
  margin: 0 0 14px;
  color: #3a2a1e;
}

/* 统计条（与 .pm-hist-stats 一致） */
.cmfhist-stats {
  display: flex; align-items: center;
  padding: 14px 0 12px;
  margin-bottom: 12px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(120, 80, 40, .07);
}
.cmfhist-stat { flex: 1 1 0; text-align: center; position: relative; }
.cmfhist-stat + .cmfhist-stat::before {
  content: ''; position: absolute; left: 0; top: 12%; bottom: 12%;
  width: 1px; background: var(--line, #ece0d3);
}
.cmfhist-num {
  font-size: 21px; font-weight: 800; line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--primary, #f95901);
}
.cmfhist-num.zero { color: var(--text2, #7a6a5c); }
.cmfhist-lbl { margin-top: 3px; font-size: 11.5px; color: var(--text2, #7a6a5c); }

/* 提示行（24 小时）＋ 右上角刷新 */
.cmfhist-tip {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 12px; margin-bottom: 12px;
  border-radius: 11px;
  background: #fff7ed; border: 1px solid #fed7aa;
  font-size: 11.5px; line-height: 1.5; color: #9a3412;
}
.cmfhist-tip > span:nth-child(2) { flex: 1 1 auto; min-width: 0; }
.cmfhist-tip b { font-weight: 800; }
.cmfhist-refresh {
  flex: 0 0 auto;
  width: 24px; height: 24px; border-radius: 8px; padding: 0;
  border: 1px solid #fed7aa; background: #fff; color: #c2410c;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; -webkit-appearance: none; appearance: none;
}
.cmfhist-refresh svg { width: 13px; height: 13px; display: block; }
.cmfhist-refresh[disabled] { opacity: .5; cursor: default; }
.cmfhist-refresh.is-spin svg { animation: cmfhistSpin .9s linear infinite; }
@keyframes cmfhistSpin { to { transform: rotate(360deg); } }

/* 列表与卡片（与 .pm-hist-list / .pm-hist-card 一致） */
.cmfhist-list { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 560px) { .cmfhist-list { grid-template-columns: 1fr 1fr; } }

.cmfhist-card {
  position: relative;
  border-radius: 15px; overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 8px rgba(120, 80, 40, .09);
  cursor: pointer;                 /* 整卡可点：打开大图 / 全文 */
}
.cmfhist-thumb {
  position: relative;
  width: 100%; aspect-ratio: 1 / 1;
  background: #f3efe9;
  display: flex; align-items: center; justify-content: center;
}
.cmfhist-thumb img,
.cmfhist-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cmfhist-ph { color: #c9a68c; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.cmfhist-ph svg { width: 30px; height: 30px; display: block; }
.cmfhist-ph span { font-size: 11px; font-weight: 700; letter-spacing: .4px; }
/* 文字类：没有缩略图，就用摘要当封面（浅底 + 顶部留白） */
.cmfhist-thumb.is-text {
  aspect-ratio: auto; min-height: 132px; align-items: flex-start; justify-content: flex-start;
  background: linear-gradient(180deg, #fffdfb 0%, #fff4ec 100%);
}
.cmfhist-tx {
  width: 100%; box-sizing: border-box;
  padding: 34px 13px 12px;
  font-size: 12px; line-height: 1.55; color: #6b5546;
  overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical;
  word-break: break-word;
}
.cmfhist-play {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255, 255, 255, .9); color: #f95901;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(70, 30, 0, .22);
  pointer-events: none;
}
.cmfhist-play svg { width: 13px; height: 13px; display: block; margin-left: 1px; }
.cmfhist-badge {
  position: absolute; top: 8px; left: 8px;
  display: flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px;
  background: rgba(20, 130, 90, .9); color: #fff;
  font-size: 10.5px; font-weight: 700;
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.cmfhist-kind {
  position: absolute; top: 8px; right: 8px;
  display: flex; align-items: center; justify-content: center;
  min-width: 26px; height: 26px; padding: 0 7px; border-radius: 999px;
  background: var(--primary, #f95901); color: #fff;
  font-size: 11.5px; font-weight: 800;
  box-shadow: 0 2px 7px rgba(0, 0, 0, .18);
}
.cmfhist-body { padding: 10px 11px 12px; }
.cmfhist-title {
  font-size: 12.5px; font-weight: 800; color: var(--text, #2b2119);
  line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.cmfhist-time {
  margin-top: 6px; font-size: 11px; color: var(--text2, #7a6a5c);
  font-variant-numeric: tabular-nums;
}
.cmfhist-ops { display: flex; gap: 7px; margin-top: 10px; }
.cmfhist-ops button,
.cmfhist-ops a {
  flex: 1 1 0; padding: 8px 0; text-align: center;
  /* 🔴 必须 display:flex + 给内嵌 svg 定尺寸：SVG 不写 width/height 时浏览器按 300×150 渲染，
     会把按钮撑成一块巨大的色块（本次实测踩到）。 */
  display: flex; align-items: center; justify-content: center; gap: 5px;
  border-radius: 10px; border: 1.4px solid var(--line, #ece0d3);
  background: #fff; color: var(--text2, #7a6a5c);
  font-family: inherit; font-size: 12px; font-weight: 700; cursor: pointer;
  text-decoration: none;
  -webkit-appearance: none; appearance: none;
}
.cmfhist-ops button svg,
.cmfhist-ops a svg { width: 13px; height: 13px; display: block; flex: 0 0 auto; }
.cmfhist-ops button.pri,
.cmfhist-ops a.pri { border-color: transparent; background: var(--primary, #f95901); color: #fff; }
.cmfhist-ops button:disabled { opacity: .5; }

/* 空态 / 加载态 */
.cmfhist-empty {
  padding: 40px 16px; text-align: center;
  border-radius: 15px; background: #fff;
  box-shadow: 0 1px 3px rgba(120, 80, 40, .06);
}
.cmfhist-empty .ico { font-size: 34px; line-height: 1; }
.cmfhist-empty .t { margin-top: 10px; font-size: 14px; font-weight: 800; color: var(--text, #2b2119); }
.cmfhist-empty .s { margin-top: 6px; font-size: 12px; line-height: 1.6; color: var(--text2, #7a6a5c); }

/* 骨架屏（首屏加载用，与卡片同尺寸，避免跳动） */
.cmfhist-sk { pointer-events: none; }
.cmfhist-sk .cmfhist-thumb { background: #f3ece5; border-bottom: 0; }
.cmfhist-sk .cmfhist-thumb::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, .75) 50%, rgba(255, 255, 255, 0) 100%);
  animation: cmfhistShim 1.15s ease-in-out infinite;
}
@keyframes cmfhistShim { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.cmfhist-sk .cmfhist-title { height: 11px; border-radius: 5px; background: #f3ece5; }
.cmfhist-sk .cmfhist-time { height: 9px; width: 46%; border-radius: 5px; background: #f6f0ea; margin-top: 8px; }
@media (prefers-reduced-motion: reduce) {
  .cmfhist-sk .cmfhist-thumb::after { animation: none; }
  .cmfhist-refresh.is-spin svg { animation: none; }
}

/* 真实读秒（不是百分比进度条） */
.cmfhist-ela { padding: 8px 2px 0; font-size: 11.5px; font-weight: 600; color: #a08c7c; text-align: center; }
.cmfhist-note b { color: #6b5546; font-weight: 700; }
.cmfhist-note button {
  border: 0; background: none; padding: 0; margin-left: 2px;
  color: #f95901; font: inherit; font-weight: 700; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
}
.cmfhist-note {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 12px;
  border: 1px dashed #ffdcbf; border-radius: 13px;
  background: #fffdfb;
  font-size: 12.5px; line-height: 1.55; color: #8a7365;
}
.cmfhist-note svg { flex: 0 0 auto; width: 15px; height: 15px; margin-top: 1px; color: #f95901; display: block; }

/* ---------- 预览弹层（点某一条后打开） ---------- */
.cmfhist-modal {
  position: fixed; inset: 0; z-index: 420;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(46, 26, 12, 0.66);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  animation: cmfhistFade .16s ease both;
}
.cmfhist-modal[hidden] { display: none !important; }
@keyframes cmfhistFade { from { opacity: 0; } to { opacity: 1; } }

.cmfhist-modal-in {
  width: 100%; max-width: 520px; max-height: 100%;
  min-width: 0;              /* 防止长内容把 flex 子项撑出视口 */
  box-sizing: border-box;
  display: flex; flex-direction: column;
  background: #fff; border-radius: 18px;
  box-shadow: 0 18px 50px rgba(60, 28, 6, 0.32);
  overflow: hidden;
  animation: cmfhistPop .2s cubic-bezier(.2, .9, .3, 1.2) both;
}
@keyframes cmfhistPop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

.cmfhist-modal-h {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid #f6ece3;
}
.cmfhist-modal-hb { flex: 1 1 auto; min-width: 0; }
.cmfhist-modal-t {
  font-size: 14.5px; font-weight: 800; color: #3a2a1e;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cmfhist-modal-d { font-size: 11.5px; color: #a08c7c; margin-top: 2px; }
.cmfhist-x {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 9px;
  border: 0; background: #fff2e8; color: #a08c7c;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; -webkit-appearance: none; appearance: none; padding: 0;
}
.cmfhist-x svg { width: 13px; height: 13px; display: block; }
.cmfhist-x:hover { background: #ffe4d3; color: #f95901; }

.cmfhist-modal-b {
  flex: 1 1 auto; min-height: 0;
  overflow: auto;
  padding: 14px;
  background: #fffdfb;
}
.cmfhist-modal-b img,
.cmfhist-modal-b video {
  display: block; width: 100%; height: auto;
  max-height: 60vh; object-fit: contain;
  border-radius: 12px; background: #2b1a10;
}
.cmfhist-modal-b audio { display: block; width: 100%; }
.cmfhist-modal-b pre {
  margin: 0; white-space: pre-wrap; word-break: break-word;
  font-family: inherit; font-size: 13px; line-height: 1.7; color: #4a382c;
}

.cmfhist-modal-f {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;              /* 窄屏时按钮换行，不挤不溢出 */
  padding: 10px 14px 14px;
  border-top: 1px solid #f6ece3;
}
.cmfhist-modal-f .cmfhist-btn { min-width: 0; }
.cmfhist-btn {
  flex: 1 1 auto; box-sizing: border-box;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 14px;
  border: 1px solid #ffdcbf; border-radius: 12px;
  background: #fff; color: #f95901;
  font-family: inherit; font-size: 13.5px; font-weight: 800;
  text-decoration: none; cursor: pointer; -webkit-appearance: none; appearance: none;
}
.cmfhist-btn svg { width: 14px; height: 14px; display: block; }
.cmfhist-btn:hover { background: #fff2e8; }
.cmfhist-btn.cmfhist-btn-main {
  border-color: transparent; color: #fff;
  background: linear-gradient(135deg, #ff8845 0%, #f95901 100%);
  box-shadow: 0 6px 16px rgba(249, 89, 1, 0.28);
}
.cmfhist-btn.cmfhist-btn-main:hover { filter: brightness(1.05); background: linear-gradient(135deg, #ff8845 0%, #f95901 100%); }

/* 轻提示：层高与位置对齐站点既有 toast 惯例
   （style.css 里 .ir-toast / .ix-toast 等均为 bottom:82px + z-index:1200），
   否则激活 / 支付层（z-index 999 / 9999）弹出来时这句提示会被吞掉。 */
.cmfhist-toast {
  position: fixed; left: 50%; bottom: 82px; z-index: 1200;
  transform: translateX(-50%);
  max-width: min(84%, 360px);
  padding: 10px 18px; border-radius: 999px;
  background: rgba(28, 20, 14, 0.9); color: #fff;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  animation: cmfhistFade .16s ease both;
  pointer-events: none;
}

/* 窄屏：页签字号收一点，图标藏掉保文字不换行（与 .pm-tabs 的处理一致） */
@media (max-width: 400px) {
  .cmfhist-tab { font-size: 12.5px; padding: 9px 2px; }
  .cmfhist-tab-ico { display: none; }
  .cmfhist-num { font-size: 19px; }
}
