/*!
 * 会话回溯（archive.css）—— Ekko 品牌层「无限上翻 + 会话内搜索」的样式
 * ---------------------------------------------------------------------------
 * 为什么要有这一层：
 *   官方聊天列表把「已加载消息」卡在 300 条（见 chatstore 的 loadOlderMessages：
 *   `if (!force && loadedMessageCount >= 300) return false`），再多就只给一条
 *   「前面的消息请到历史记录查看」的链接，而那个链接指向的 /hermes/history 页
 *   在本实例上数据源是 500。所以会话一旦长了，桌面和手机都"翻不上去"。
 *   这里补一个只读的回溯视图：直接用官方的
 *   /api/studio/sessions/conversations/{id}/messages/paginated 一页一页往回拉，
 *   拉到底为止（真·无限），并顺手做会话内全文搜索。
 *
 * 规矩跟其它品牌层一致：
 *   · 名字全部锁在 #ekko-archive / .ea- 前缀下，不碰官方任何选择器，
 *     唯一的例外是给官方那条 .history-archive-link 换文案（功能接管，不是样式覆盖）；
 *   · 颜色一律走官方 CSS 变量，深浅色自动跟随，不写死 #fff；
 *   · z-index 1400：官方 studio-page-header 是 1001、web-pet 是 1200，再低会被压住。
 *
 * 2026-10-28 新建。
 */

/* ── 会话页右上角的入口按钮 ───────────────────────────────────
   正常情况下 archive.js 会把它塞进官方 .chat-header .header-actions 里，
   跟官方按钮同排、贴着右上角；官方重渲染导致节点被回收时，降级成浮动按钮。 */
.ea-entry {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border-light, rgba(128, 128, 128, .28));
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary, #666);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.ea-entry:hover {
  color: var(--accent-primary, #233176);
  border-color: var(--accent-primary, #233176);
  background: color-mix(in srgb, var(--accent-primary, #233176) 8%, transparent);
}
.ea-entry svg { width: 15px; height: 15px; flex: 0 0 auto; }
.ea-entry span.ea-entry-txt { display: none; }
@media (min-width: 1100px) {
  .ea-entry span.ea-entry-txt { display: inline; }
}
.ea-entry--float {
  position: fixed;
  top: 10px;
  right: 12px;
  z-index: 1300;
  background: var(--bg-primary, #fff);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
}
html.ekko-m .ea-entry--float { top: calc(6px + env(safe-area-inset-top, 0px)); }

/* ── 回溯页本体 ──────────────────────────────────────────── */
#ekko-archive {
  position: fixed;
  inset: 0;
  z-index: 1400;
  display: none;
  flex-direction: column;
  background: var(--bg-primary, #fff);
  color: var(--text-primary, #1a1a1a);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
html.ea-open #ekko-archive { display: flex; }
html.ea-open, html.ea-open body { overflow: hidden; }

#ekko-archive *,
#ekko-archive *::before,
#ekko-archive *::after { box-sizing: border-box; }

/* 顶栏：关闭 / 标题 / 搜索 / 命中导航 / 视图切换 */
.ea-top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border-light, rgba(128, 128, 128, .18));
  background: var(--bg-primary, #fff);
}
.ea-top-title {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-right: auto;
}
.ea-top-title b {
  font-size: 14px;
  font-weight: 600;
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ea-top-title small {
  font-size: 11px;
  color: var(--text-secondary, #888);
}
.ea-iconbtn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary, #666);
  cursor: pointer;
}
.ea-iconbtn:hover { background: var(--bg-hover, rgba(128, 128, 128, .12)); color: var(--text-primary, #1a1a1a); }
.ea-iconbtn[disabled] { opacity: .4; cursor: default; }
.ea-iconbtn svg { width: 18px; height: 18px; }

/* 搜索区 */
.ea-search {
  flex: 0 1 320px;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border-light, rgba(128, 128, 128, .28));
  border-radius: 8px;
  background: var(--bg-card, rgba(128, 128, 128, .06));
}
.ea-search input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  font-size: 13px;
}
.ea-search svg { width: 15px; height: 15px; flex: 0 0 auto; color: var(--text-secondary, #888); }
.ea-search button { border: 0; background: transparent; color: var(--text-secondary, #888); cursor: pointer; padding: 0; display: inline-flex; }
.ea-hitnav { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.ea-hitnav span {
  font-size: 12px;
  color: var(--text-secondary, #888);
  min-width: 52px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* 体区：结果列表 / 全文列表 同时挂在 DOM 里，靠 ea-mode 切 */
.ea-stage { position: relative; flex: 1 1 auto; min-height: 0; }
.ea-body,
.ea-results {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 12px 0 12px;
}
#ekko-archive[data-mode="msgs"] .ea-results { display: none; }
#ekko-archive[data-mode="hits"] .ea-body { display: none; }

/* 全文列表 */
.ea-msgs { width: 100%; max-width: 900px; margin: 0 auto; padding: 0 14px; }
.ea-more {
  display: block;
  width: 100%;
  margin: 6px 0 14px;
  padding: 9px;
  border: 1px dashed var(--border-light, rgba(128, 128, 128, .3));
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary, #888);
  font-size: 12px;
  cursor: pointer;
}
.ea-more[disabled] { cursor: default; opacity: .7; }

.ea-msg { margin: 0 0 14px; }
.ea-msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--text-secondary, #888);
}
.ea-msg-role {
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--bg-card, rgba(128, 128, 128, .1));
  color: var(--text-secondary, #666);
}
.ea-msg--user .ea-msg-role { background: var(--accent-primary, #233176); color: #fff; }
.ea-msg-body {
  padding: 9px 12px;
  border: 1px solid var(--border-light, rgba(128, 128, 128, .16));
  border-radius: 10px;
  background: var(--bg-card, rgba(128, 128, 128, .05));
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 13.5px;
  line-height: 1.65;
}
.ea-msg--tool .ea-msg-body {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-secondary, #777);
}
.ea-msg--tool.ea-collapsed .ea-msg-body { display: none; }
.ea-msg-toggle {
  margin-top: 4px;
  border: 0;
  background: transparent;
  padding: 0;
  font-size: 11.5px;
  color: var(--accent-primary, #233176);
  cursor: pointer;
}
.ea-msg--tool > .ea-msg-head { cursor: pointer; }
.ea-msg mark {
  background: #ffe08a;
  color: #1a1a1a;
  border-radius: 2px;
  padding: 0 1px;
}
html.dark .ea-msg mark { background: #7a5c12; color: #ffe9b0; }
.ea-msg.is-cur .ea-msg-body { border-color: var(--accent-primary, #233176); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-primary, #233176) 25%, transparent); }

/* 结果列表 */
.ea-results-inner { width: 100%; max-width: 900px; margin: 0 auto; padding: 0 14px; }
.ea-hit {
  display: block;
  width: 100%;
  text-align: left;
  margin: 0 0 8px;
  padding: 10px 12px;
  border: 1px solid var(--border-light, rgba(128, 128, 128, .16));
  border-radius: 10px;
  background: var(--bg-card, rgba(128, 128, 128, .05));
  color: inherit;
  cursor: pointer;
}
.ea-hit:hover { border-color: var(--accent-primary, #233176); }
.ea-hit-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 11px;
  color: var(--text-secondary, #888);
}
.ea-hit-snip {
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-height: 5.2em;
  overflow: hidden;
}
.ea-hit mark { background: #ffe08a; color: #1a1a1a; border-radius: 2px; padding: 0 1px; }
html.dark .ea-hit mark { background: #7a5c12; color: #ffe9b0; }

/* 底部浮动：命中跳转 + 状态 */
.ea-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border-light, rgba(128, 128, 128, .18));
  font-size: 12px;
  color: var(--text-secondary, #888);
}
.ea-foot .ea-foot-txt { margin-right: auto; }
.ea-chipbar { display: flex; gap: 6px; }
.ea-chip {
  padding: 4px 10px;
  border: 1px solid var(--border-light, rgba(128, 128, 128, .28));
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary, #666);
  font-size: 12px;
  cursor: pointer;
}
.ea-chip.on {
  color: #fff;
  background: var(--accent-primary, #233176);
  border-color: var(--accent-primary, #233176);
}
.ea-empty { padding: 40px 14px; text-align: center; color: var(--text-secondary, #888); font-size: 13px; }

/* 加载/扫描中的细进度条 */
.ea-prog {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  overflow: hidden;
  pointer-events: none;
}
.ea-prog i {
  display: block;
  width: 32%;
  height: 100%;
  background: var(--accent-primary, #233176);
  animation: ea-slide 1s linear infinite;
}
@keyframes ea-slide {
  from { transform: translateX(-100%); }
  to { transform: translateX(320%); }
}

/* 官方那条「前面的消息请到历史记录查看」被接管成上翻加载指示：
   文字去掉，只留一个转圈；滚到顶自动拉，不用点。
   选择器带上 a/标签+双重类名，是为了压过官方 MessageList 的 scoped 样式
   （那个 css 是动态 chunk，注入顺序在我们后面）。 */
a.history-archive-link.ea-more-link {
  min-width: 44px;
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--accent-primary, #333);
  cursor: default;
  -webkit-tap-highlight-color: transparent;
}
a.history-archive-link.ea-more-link:hover { background: transparent; }
a.history-archive-link.ea-more-link .ea-spin {
  display: block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(var(--accent-primary-rgb, 51, 51, 51), .18);
  border-top-color: currentColor;
  border-radius: 50%;
  opacity: .35;
  animation: ea-spin 1.4s linear infinite paused;
  animation-play-state: paused;
  transition: opacity .18s linear;
}
a.history-archive-link.ea-more-link.is-loading .ea-spin {
  opacity: .9;
  animation-duration: .72s;
  animation-play-state: running;
}
@keyframes ea-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  a.history-archive-link.ea-more-link.is-loading .ea-spin { animation-duration: 1.6s; }
}

/* 手机：整屏覆盖，顶栏稍微矮一点 */
@media (max-width: 768px) {
  .ea-top { height: 52px; padding: 0 10px; gap: 8px; }
  .ea-search { flex: 1 1 auto; }
  .ea-msgs, .ea-results-inner { padding: 0 10px; }
  .ea-msg-head { font-size: 10.5px; }
}
