/* ============================================================
   口袋48 房间消息 —— 视觉规范
   ------------------------------------------------------------
   冷蓝画布 + 白色纸卡，唯一高饱和蓝做「动作/时间码」，
   琥珀色留给命中高亮与成员强调。克制、左对齐、大点击区、
   无多余动效。复刻「回放弹幕检索」的风格基调。
   ============================================================ */
:root {
  --bg: #e9f0f6;
  --glow: rgba(30, 144, 224, 0.10);
  --card: #ffffff;
  --ink: #14283c;
  --muted: #5e7488;
  --faint: #93a7b8;
  --line: #d6e1eb;
  --line-strong: #c2d2e0;
  --primary: #0b7ec4;
  --primary-deep: #09679f;
  --primary-soft: #e1f0fb;
  --accent: #efa600;
  --mark: #ffe9ab;
  --member-bg: #fff6df;
  --danger: #c23a30;
  --ok: #1f9d55;
  --radius: 14px;
  --shadow: 0 1px 0 rgba(20, 40, 60, 0.03), 0 10px 24px -14px rgba(20, 40, 60, 0.18);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  font-size: 15px;
  min-height: 100vh;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
input, textarea, select { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
img, svg { -webkit-user-drag: none; user-drag: none; }
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto 0;
  height: 40vh;
  background: radial-gradient(120% 90% at 50% -10%, var(--glow), transparent 70%);
  pointer-events: none;
  z-index: 0;
}
button, input, select { font: inherit; color: inherit; }
button, a { -webkit-touch-callout: none; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.app {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(18px + var(--safe-b));
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(12px + var(--safe-t)) 16px 10px;
  background: linear-gradient(180deg, rgba(233, 240, 246, 0.96), rgba(233, 240, 246, 0.82));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(194, 210, 224, 0.7);
}
.topbar .brand { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.2px;
  color: var(--ink);
}
.topbar .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--ink);
  text-decoration: none;
}
.icon-btn:active { background: var(--primary-soft); }

.view { padding: 14px 16px 0; }

/* ---------- 检索表单卡片 ---------- */
.form-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 14px;
}
.member-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.member-avatar {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--primary-soft);
}
.member-pick .who { flex: 1; min-width: 0; }
.member-pick .who .name { font-size: 16px; font-weight: 800; }
.member-pick .who .team { font-size: 12px; color: var(--muted); }
.member-pick .pick-btn {
  flex: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--primary-deep);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.member-pick .pick-btn:active { background: var(--primary-soft); }

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.search-input {
  flex: 1;
  min-width: 0;
  height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 15px;
  background: var(--card);
  color: var(--ink);
}
.search-input::placeholder { color: var(--faint); }
.search-input:focus { border-color: var(--primary); outline: none; }
.search-btn {
  flex: none;
  height: 44px;
  padding: 0 18px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.search-btn:active { background: var(--primary-deep); }

.date-row { display: flex; gap: 8px; margin-bottom: 10px; }
.date-field {
  flex: 1;
  min-width: 0;
  height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 0 10px;
  font-size: 14px;
  background: var(--card);
  color: var(--ink);
}
.date-field:focus { border-color: var(--primary); outline: none; }
.date-sep { align-self: center; color: var(--faint); font-size: 13px; }

.tool-row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}
.sort-seg { display: flex; gap: 6px; }
.sort-seg .seg {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.sort-seg .seg.on { background: var(--primary-deep); border-color: var(--primary-deep); color: #fff; }
.hint { font-size: 12px; color: var(--faint); }

/* ---------- 结果统计与列表 ---------- */
.result-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 2px 2px 10px;
  font-size: 12px;
  color: var(--muted);
}
.result-meta .count { font-weight: 700; color: var(--ink); }

.msg-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.msg-card:active { background: #f7fbff; }
.msg-card .head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.msg-card .m-avatar {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--primary-soft);
}
.msg-card .m-name { font-size: 13px; font-weight: 700; color: var(--ink); }
.msg-card .m-name .idol-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-size: 11px;
  font-weight: 700;
}
.msg-card .m-name .room-tag {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 6px;
  border-radius: 6px;
  background: #eef1f4;
  color: #65717d;
  font-size: 11px;
  font-weight: 700;
}
.msg-card .m-time { margin-left: auto; font-size: 12px; color: var(--faint); flex: none; }
.msg-card .body { font-size: 15px; color: var(--ink); white-space: pre-wrap; word-break: break-word; }
.msg-card .body mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.msg-card .meta-line { margin-top: 6px; font-size: 13px; color: var(--muted); }
.msg-card .replied {
  margin-top: 6px;
  padding: 6px 9px;
  border-left: 3px solid var(--primary-soft);
  color: var(--muted);
  font-size: 13px;
  background: #f7fafc;
  border-radius: 0 8px 8px 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-card .placeholder { font-size: 14px; color: var(--primary); font-weight: 600; }
.media-thumb {
  display: block;
  margin-top: 8px;
  max-width: 160px;
  max-height: 160px;
  border-radius: 10px;
  border: 1px solid var(--line);
}

/* 加载更多 */
.load-more {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 4px 0 10px;
  border: 1px dashed var(--line-strong);
  background: transparent;
  color: var(--primary-deep);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.load-more:active { background: var(--primary-soft); }
.load-more[disabled] { color: var(--faint); cursor: default; }

/* 空态 / 提示 */
.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--faint);
  font-size: 14px;
}
.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 成员选择浮层 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 30, 45, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 720px;
  max-height: 84vh;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -8px 30px rgba(20, 40, 60, 0.25);
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.sheet-head .search-input { height: 40px; }
.sheet-close {
  flex: none;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 18px;
  cursor: pointer;
}
.sheet-body { overflow-y: auto; padding: 10px 16px 24px; flex: 1; }
.sheet-group { margin-bottom: 4px; }
.sheet-group .g-title {
  margin: 12px 2px 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.4px;
}
.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.member-item:active { background: var(--primary-soft); }
.member-item .a {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  object-fit: cover;
  background: var(--primary-soft);
}
.member-item .n { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; }
.member-item .t { font-size: 12px; color: var(--faint); flex: none; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-item .star { flex: none; color: var(--accent); font-size: 16px; cursor: pointer; }
.member-item.on { background: var(--primary-soft); }

/* ---------- 上下文抽屉 ---------- */
.ctx-drawer {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: rgba(15, 30, 45, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.ctx-sheet {
  width: 100%;
  max-width: 720px;
  max-height: 86vh;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -8px 30px rgba(20, 40, 60, 0.25);
}
.ctx-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.ctx-head .title { flex: 1; min-width: 0; font-size: 14px; font-weight: 800; }
.ctx-body { overflow-y: auto; padding: 12px 14px 24px; flex: 1; }
.ctx-msg {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.ctx-msg.target { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.ctx-msg.is-member { background: var(--member-bg); border-color: #eed9a0; }
.ctx-msg .head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.ctx-msg .who { font-size: 12px; font-weight: 700; }
.ctx-msg .idol-tag {
  display: inline-block;
  padding: 0 5px;
  border-radius: 5px;
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-size: 10px;
  font-weight: 700;
}
.ctx-msg .tm { margin-left: auto; font-size: 11px; color: var(--faint); flex: none; }
.ctx-msg .body { font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.ctx-msg .body mark { background: var(--mark); border-radius: 3px; padding: 0 1px; }
.ctx-msg .ph { font-size: 13px; color: var(--primary); font-weight: 600; }

@media (min-width: 720px) {
  .overlay, .ctx-drawer { align-items: center; }
  .sheet, .ctx-sheet { border-radius: 18px; }
}

/* ---------- 命中别名标签（追踪页） ---------- */
.hit-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.alias-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-size: 11px;
  font-weight: 700;
}

/* 马甲昵称（真实名旁的小字） */
.m-nick {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  margin-left: 6px;
}

/* 实时来源标记（牙牙推送，2~6秒延迟） */
.rt-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 6px;
  background: #e6f7ec;
  color: #1d8b5d;
  font-size: 11px;
  font-weight: 700;
}
/* 上下文底部说明 */
.ctx-note {
  margin: 10px 2px 0;
  font-size: 12px;
  color: var(--faint);
  text-align: center;
}

/* 「本人 / 其他成员」切换 */
.mode-seg {
  flex: none;
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
}
.mode-seg button {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 0 12px;
  height: 38px;
  cursor: pointer;
  white-space: nowrap;
}
.mode-seg button + button { border-left: 1px solid var(--line); }
.mode-seg button.on {
  background: var(--primary-deep);
  color: #fff;
}
.mode-seg button:not(.on):active { background: var(--primary-soft); }

/* ============ 左滑露出 ✕ + 5秒撤销 ============ */
.msg-wrap {
  position: relative;
  margin-bottom: 10px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--danger);
}
.msg-wrap .msg-card { margin-bottom: 0; position: relative; z-index: 1; will-change: transform; }
.msg-wrap .msg-card.swiping { transition: none; }
.msg-wrap .msg-card:not(.swiping) { transition: transform 0.18s ease; }
.msg-wrap.revealed .msg-card { transform: translateX(-72px); }
.msg-wrap .msg-del {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 72px;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.msg-wrap .msg-del:active { background: #a92f26; }

/* 撤销提示条（底部居中，5秒自动消失） */
.undo-toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: min(92vw, 420px);
  padding: 10px 12px 10px 16px;
  border-radius: 12px;
  background: rgba(20, 40, 60, 0.94);
  color: #fff;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(10, 25, 40, 0.3);
  animation: toastIn 0.18s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }
.undo-toast .undo-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.undo-toast .undo-btn {
  flex: none;
  border: none;
  background: var(--primary-soft);
  color: var(--primary-deep);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

/* 删除动画：高度塌缩（仅这一张卡片重排） */
.msg-wrap.removing {
  transition: height 0.2s ease, opacity 0.2s ease, margin-bottom 0.2s ease;
  pointer-events: none;
}

/* 懒渲染哨兵 */
.render-more { min-height: 8px; }

/* 上下文里的多媒体 */
.media-video {
  display: block;
  margin-top: 8px;
  width: 100%;
  max-width: 320px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #000;
}
.media-audio {
  display: block;
  margin-top: 8px;
  width: 100%;
  max-width: 320px;
}

/* 头像：首字兜底 + 图片覆盖（加载中/失败都不出现空框） */
.m-avatar-wrap {
  flex: none;
  position: relative;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-size: 13px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.m-avatar-wrap::before { content: attr(data-initial); }
.m-avatar-wrap .m-avatar {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  object-fit: cover;
  background: var(--primary-soft);
}

/* ============ 吸顶头部（顶栏 + 筛选栏） ============ */
.sticky-head {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, rgba(233, 240, 246, 0.98), rgba(233, 240, 246, 0.92));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(194, 210, 224, 0.75);
}
.sticky-head .topbar {
  position: static;
  border-bottom: none;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  padding-bottom: 6px;
}
.sticky-head .filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 10px;
}
.filter-bar .fb-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 8px;
  height: 34px;
}
.filter-bar input {
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--ink);
  outline: none;
  width: 118px;
  max-width: 40vw;
}
.filter-bar input::placeholder { color: var(--faint); }
.filter-bar input[type="date"] { width: 116px; }
.filter-bar input[type="date"]::-webkit-calendar-picker-indicator { opacity: 0.5; }

/* 成员建议框：只在打字时出现，限高，不遮挡键盘 */
.filter-bar .fb-item { position: relative; }
.member-suggest {
  position: absolute;
  top: 38px;
  left: 0;
  z-index: 40;
  min-width: 150px;
  max-width: 70vw;
  max-height: 172px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 10px 24px -10px rgba(20, 40, 60, 0.35);
}
.member-suggest[hidden] { display: none; }
.member-suggest button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
}
.member-suggest button + button { border-top: 1px solid var(--line); }
.member-suggest button:active { background: var(--primary-soft); }

/* 成员框展开按钮 */
.filter-bar .fb-expand {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 0 2px 0 4px;
  cursor: pointer;
}
.filter-bar .fb-expand:active { color: var(--primary-deep); }

/* 清空日期按钮 */
.filter-bar .fb-clear {
  height: 34px;
  padding: 0 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  background: transparent;
  color: var(--primary-deep);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.filter-bar .fb-clear:active { background: var(--primary-soft); }

/* 统计行提示 */
.result-meta { flex-wrap: wrap; }
.meta-tip {
  flex-basis: 100%;
  margin-top: 4px;
  font-size: 11px;
  color: var(--faint);
}

.meta-updating { color: var(--primary-deep); }

/* 引用粉丝原话：明确的引用卡片 */
.replied {
  margin-top: 8px;
  padding: 8px 10px;
  border-left: 3px solid var(--primary);
  background: #f4f8fb;
  border-radius: 0 8px 8px 0;
}
.replied-head {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary-deep);
  margin-bottom: 3px;
}
.replied-text {
  font-size: 13px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}
.replied-text mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.ctx-msg .replied { margin-top: 6px; }

/* 日期为空时（全部时间）的提示 */
.filter-bar input[type="date"]:not(:focus):invalid { color: var(--faint); }
