:root {
  --bg: #ededed;
  --panel: #fff;
  --border: #e5e5e5;
  --text: #191919;
  --muted: #888;
  --muted-2: #b4b4b4;
  --accent: #07c160;
  --me: #95ec69;
  --her: #ffffff;
  --shadow: rgba(0,0,0,0.06);
  --me-tint: #e6f7d4;
  --her-tint: #f4f6f8;

  /* 聊天背景图 —— 上传 OSS 后改这一行就行 */
  --chat-bg-image: url('https://wx-with-shuoshuo.oss-cn-qingdao.aliyuncs.com/bg.jpg');
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

/* ---------- gate ---------- */
.gate {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #f5f5f7 0%, #e6e8ec 100%);
  z-index: 999; padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
.gate-box {
  background: var(--panel);
  padding: 32px 40px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
  width: 100%; max-width: 320px;
  text-align: center;
}
.gate-box h2 {
  margin: 0 0 6px; font-size: 20px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.gate-hint { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.gate-box input {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.gate-box input:focus { border-color: var(--accent); }
.gate-box button {
  margin-top: 12px; width: 100%; padding: 12px;
  background: var(--accent); color: white; border: 0; border-radius: 8px;
  font-size: 15px; cursor: pointer; font-weight: 500;
}
.gate-box button:hover { background: #06ad55; }
.gate-box button:disabled { opacity: 0.7; }
.gate-err { color: #d32f2f; font-size: 12px; margin-top: 8px; min-height: 16px; }

.ic { width: 20px; height: 20px; vertical-align: -4px; flex-shrink: 0; }
.ic-sm { width: 14px; height: 14px; vertical-align: -2px; }
.ic-lock { width: 22px; height: 22px; }

/* ---------- app shell ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; height: 100vh; }

/* 极简 topbar：只有名字 + 搜索按钮 */
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 12px;
  padding-top: env(safe-area-inset-top);
  min-height: calc(48px + env(safe-area-inset-top));
  flex-shrink: 0;
  position: relative;
}
.topbar h1 {
  margin: 0; font-size: 17px; font-weight: 600;
  position: absolute; left: 0; right: 0; top: env(safe-area-inset-top);
  height: 48px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.icon-btn {
  margin-left: auto; z-index: 1;
  width: 36px; height: 36px;
  border: 0; background: transparent; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: rgba(0,0,0,0.06); }

/* ---------- messages ---------- */
.messages {
  flex: 1; overflow-y: auto;
  padding: 8px 0;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  position: relative;
  -webkit-overflow-scrolling: touch;
  overflow-anchor: auto;
  scroll-behavior: auto;

  background-color: var(--bg);
  background-image: var(--chat-bg-image, none);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}
.msg-stream { max-width: 760px; margin: 0 auto; padding: 0 14px; }

.hint {
  text-align: center; font-size: 11px;
  padding: 10px 0; user-select: none;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  color: rgba(0,0,0,0.5);
}

/* WeChat 日期胶囊 */
.day-header { text-align: center; margin: 14px 0 10px; font-size: 11px; }
.day-header > span {
  display: inline-block;
  padding: 3px 10px;
  background: rgba(0,0,0,0.22);
  color: #fff;
  border-radius: 4px;
  letter-spacing: 0.2px;
}

/* 返回搜索 sticky pill */
.back-search-bar {
  position: sticky; top: 0; z-index: 50;
  display: flex; justify-content: center;
  padding: 8px 0 4px; pointer-events: none;
}
.back-search-bar > button {
  pointer-events: auto;
  background: rgba(7,193,96,0.95);
  color: #fff; border: 0;
  padding: 7px 14px;
  border-radius: 18px;
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,0.18);
  display: flex; align-items: center; gap: 4px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.back-search-bar > button:active { transform: scale(0.97); }

/* ---------- 气泡 ---------- */
.msg {
  display: flex; margin: 4px 0; gap: 8px;
  align-items: flex-start;
}
.msg.me { justify-content: flex-end; }
.msg.her { justify-content: flex-start; }
.avatar {
  width: 36px; height: 36px; border-radius: 4px;
  object-fit: cover; flex-shrink: 0;
  background: var(--border);
}
.bubble {
  position: relative;
  max-width: calc(100% - 96px);
  padding: 8px 12px;
  border-radius: 4px;
  word-break: break-word; white-space: pre-wrap;
  box-shadow: 0 1px 1px var(--shadow);
  line-height: 1.5;
}
.msg.me .bubble { background: var(--me); }
.msg.her .bubble { background: var(--her); }
.msg.me .bubble::after {
  content: ''; position: absolute;
  right: -5px; top: 8px;
  border: 5px solid transparent;
  border-left-color: var(--me);
  border-right-width: 0;
}
.msg.her .bubble::before {
  content: ''; position: absolute;
  left: -5px; top: 8px;
  border: 5px solid transparent;
  border-right-color: var(--her);
  border-left-width: 0;
}
.msg .time {
  font-size: 11px; color: var(--muted);
  flex-shrink: 0; align-self: flex-end; margin-bottom: 4px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  opacity: 0.55;
}

.placeholder { color: var(--muted); font-style: italic; }
.voice-content { display: flex; flex-direction: column; gap: 4px; }
.voice-transcript { color: #555; font-size: 13px; display: flex; align-items: flex-start; gap: 6px; }
.voice-transcript .ic { color: var(--muted); margin-top: 2px; }

.bubble img {
  max-width: 100%; border-radius: 4px; display: block; cursor: zoom-in;
  min-height: 80px;
  background: rgba(0,0,0,0.04);
}
.bubble video {
  max-width: 100%; border-radius: 4px;
  min-height: 140px;
  background: rgba(0,0,0,0.04);
}
.bubble audio { width: 240px; max-width: 100%; }

mark { background: #fff2a8; padding: 0 2px; border-radius: 2px; }

.highlight-flash { animation: flash 1.6s ease-out; }
@keyframes flash {
  0%   { box-shadow: 0 0 0 3px rgba(255,200,0,0.7); }
  100% { box-shadow: 0 0 0 0  rgba(255,200,0,0);   }
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex; flex-direction: column;
  animation: slide-in 0.22s ease-out;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.overlay-dark { background: #111; color: #fff; }
@keyframes slide-in {
  from { transform: translateX(20%); opacity: 0; }
  to   { transform: translateX(0);   opacity: 1; }
}

.overlay-header {
  display: flex; align-items: center;
  padding: 8px 4px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  min-height: 48px;
  flex-shrink: 0;
}
.overlay-dark .overlay-header {
  background: #111; color: #fff;
  border-bottom: 1px solid #222;
}
.overlay-header h2 {
  flex: 1; text-align: center; margin: 0;
  font-size: 16px; font-weight: 600;
}
.back-btn {
  background: transparent; border: 0;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  color: inherit; cursor: pointer;
  border-radius: 50%;
}
.back-btn:active { background: rgba(0,0,0,0.06); }
.overlay-dark .back-btn:active { background: rgba(255,255,255,0.1); }

/* ---------- 搜索 overlay ---------- */
.search-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.search-input-wrap {
  flex: 1;
  display: flex; align-items: center; gap: 6px;
  background: #fff; border-radius: 8px;
  padding: 7px 10px;
}
.search-input-wrap > svg { color: var(--muted-2); flex-shrink: 0; }
.search-input-wrap > input {
  flex: 1; border: 0; outline: 0; background: transparent;
  font-size: 16px; font-family: inherit;
  min-width: 0;
}
#search-clear-inline {
  flex-shrink: 0;
  width: 18px; height: 18px;
  border: 0; border-radius: 50%;
  background: rgba(0,0,0,0.18); color: #fff;
  font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.cancel-btn {
  background: transparent; border: 0;
  color: var(--text); font-size: 15px;
  padding: 4px 4px; cursor: pointer;
  flex-shrink: 0;
}
.cancel-btn:active { color: var(--accent); }

/* shortcut tiles */
.search-shortcuts {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column;
}
.search-shortcuts .hint {
  padding: 32px 0 18px; font-size: 13px; color: var(--muted);
}
.shortcut-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  background: var(--panel);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.shortcut {
  appearance: none;
  background: transparent; border: 0;
  border-right: 1px solid var(--border);
  padding: 16px 8px;
  font-size: 14px; color: var(--text);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  min-height: 56px;
}
.shortcut:last-child { border-right: 0; }
.shortcut:active { background: rgba(0,0,0,0.04); }

.overlay-footer {
  margin-top: auto;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  color: var(--muted-2);
}
#logout-link {
  background: transparent; border: 0;
  color: #e94545; font-size: 14px; cursor: pointer;
  padding: 8px 16px;
}
.meta-info { font-size: 11px; color: var(--muted-2); }

/* 搜索结果 */
.search-results-area {
  flex: 1; overflow-y: auto;
  background: var(--bg);
}
.search-summary {
  font-size: 13px; color: #444;
  padding: 12px 16px 6px;
  background: var(--bg);
}
.search-summary b { color: var(--accent); }
.search-result {
  background: var(--panel);
  margin: 0 12px 8px;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex; gap: 10px; align-items: flex-start;
  border-left: 3px solid transparent;
}
.search-result:active { background: #f8f8f8; }
.search-result.me  { border-left-color: var(--accent); }
.search-result.her { border-left-color: #4e8df0; }
.search-result .avatar { width: 32px; height: 32px; }
.search-result .sr-content { flex: 1; min-width: 0; }
.search-result .sr-meta { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.search-result .sr-name { font-weight: 600; color: var(--text); }
.search-result .sr-body { font-size: 14px; line-height: 1.45; word-break: break-word; max-height: 60px; overflow: hidden; }
.search-result mark { background: #fff2a8; padding: 0 2px; border-radius: 2px; }
.search-result img { max-width: 140px; max-height: 120px; border-radius: 4px; }
.search-result video { max-width: 180px; max-height: 140px; border-radius: 4px; }
.search-result audio { max-width: 200px; }

/* ---------- 日期 overlay：连续月份列表 ---------- */
.date-calendar {
  flex: 1; overflow-y: auto;
  background: #fff;
  padding-bottom: env(safe-area-inset-bottom);
}
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--muted-2);
  font-size: 13px;
  padding: 12px 4px 10px;
  background: #fff;
  border-bottom: 1px solid #f0f0f0;
  position: sticky; top: 0; z-index: 10;
}
.cal-month-title {
  padding: 18px 20px 6px;
  font-size: 14px;
  color: var(--muted);
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 2px 4px 10px;
}
.cal-day {
  position: relative;
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  color: var(--text);
}
.cal-day .cal-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  font-variant-numeric: tabular-nums;
}
.cal-day.empty,
.cal-day.disabled { color: rgba(0,0,0,0.18); }
.cal-day[data-d] { cursor: pointer; }
.cal-day[data-d]:active .cal-num { background: rgba(7,193,96,0.12); }
.cal-day.today .cal-num {
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}
.cal-lbl {
  position: absolute;
  bottom: 4px; left: 0; right: 0;
  text-align: center;
  font-size: 10px;
  color: var(--accent);
}

/* ---------- 图片视频 overlay ---------- */
.gallery-header { background: #111; color: #fff; }
.gallery-tabs {
  flex: 1;
  display: flex; justify-content: center; gap: 6px;
  background: rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 3px;
  max-width: 240px;
  margin: 0 auto;
}
.gtab {
  background: transparent; border: 0;
  color: rgba(255,255,255,0.7);
  padding: 6px 14px; border-radius: 16px;
  font-size: 13px; cursor: pointer;
}
.gtab.active { background: rgba(255,255,255,0.18); color: #fff; }

.gallery-grid {
  flex: 1; overflow-y: auto; padding: 0 0 16px;
}
.gallery-month {
  padding: 12px 12px 6px; color: rgba(255,255,255,0.8); font-size: 13px;
}
.gallery-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 0 2px;
}
.gcell {
  position: relative; aspect-ratio: 1;
  background: #222;
  overflow: hidden;
  cursor: pointer;
}
.gcell img, .gcell video {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.video-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.25);
}
/* lazy-img has no src until IntersectionObserver fires; gcell background acts as placeholder */
.lazy-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gcell .video-badge {
  position: absolute; left: 6px; bottom: 6px;
  background: rgba(0,0,0,0.6); color: #fff;
  padding: 1px 6px; border-radius: 4px;
  font-size: 11px;
  display: flex; align-items: center; gap: 3px;
}
.gallery-loading { padding: 60px 0; text-align: center; color: rgba(255,255,255,0.6); font-size: 13px; }
.gallery-empty { padding: 60px 0; text-align: center; color: rgba(255,255,255,0.5); font-size: 14px; }

.gallery-jump-icon { color: rgba(255,255,255,0.75); margin-left: auto; }
.gallery-jump-icon:active { background: rgba(255,255,255,0.12); }

.gallery-month-list {
  flex: 1; overflow-y: auto;
  padding: 4px 0 calc(16px + env(safe-area-inset-bottom));
}
.gallery-month-item {
  width: 100%; background: transparent;
  border: 0; border-bottom: 1px solid #222;
  padding: 15px 20px;
  display: flex; align-items: center; justify-content: space-between;
  color: #fff; font-family: inherit; font-size: 15px;
  cursor: pointer; text-align: left;
}
.gallery-month-item:active { background: rgba(255,255,255,0.08); }
.gallery-month-count { color: rgba(255,255,255,0.38); font-size: 13px; }
.gallery-date-month-header {
  padding: 14px 20px 4px;
  font-size: 12px; letter-spacing: 0.4px;
  color: rgba(255,255,255,0.4);
  border-bottom: 1px solid #1a1a1a;
}
.gallery-date-item { padding-left: 32px; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.94);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; cursor: zoom-out;
}
.lightbox img { max-width: 96vw; max-height: 86vh; }
.lb-context {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,0.18);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff; border: 0;
  padding: 9px 18px; border-radius: 20px;
  font-size: 13px; cursor: pointer;
}

/* ---------- floating btn ---------- */
.floating-btn {
  position: fixed; right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 44px; height: 44px;
  border: 0; border-radius: 22px;
  background: var(--accent); color: white;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
  display: flex; align-items: center; justify-content: center;
}
.floating-btn:hover { background: #06ad55; }
.floating-btn svg { width: 18px; height: 18px; }

/* ---------- mobile tweaks ---------- */
@media (max-width: 720px) {
  .msg-stream { padding: 0 8px; }
  .bubble { max-width: calc(100% - 80px); font-size: 15px; }
  .bubble img { max-width: 220px; }
  .bubble video { max-width: 240px; }
  .gallery-row { grid-template-columns: repeat(3, 1fr); }
  .floating-btn { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
}
@media (max-width: 400px) {
  .topbar h1 { font-size: 16px; }
  .day-header { font-size: 11px; margin: 12px 0 8px; }
  .bubble { padding: 7px 10px; font-size: 14px; }
  .bubble img { max-width: 180px; }
}
