/* ============================================================
 * OpenChat Design System — 应用层
 * 
 * 把 tokens 翻译成具体组件的样式, 体现灵魂
 * ============================================================ */

/* === 全局基线 === */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: var(--font-stack);
  font-size: var(--fs-base);
  font-weight: var(--fw-regular);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern", "liga", "calt";
  letter-spacing: -0.01em;
  color: var(--text-1);
  background: var(--bg-base);
  min-height: 100dvh;
  min-height: 100vh;
}

::selection {
  background: var(--brand-500);
  color: white;
}

/* === 标题 — 不需要的时候 === */
h1, h2, h3, h4 { margin: 0; font-weight: var(--fw-semibold); }

/* === 链接 === */
a {
  color: var(--brand-500);
  text-decoration: none;
  transition: opacity var(--t-fast) var(--ease-out);
}
a:hover { opacity: 0.8; }

/* === 按钮 — 三种语境 === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: var(--h-btn);
  padding: 0 var(--sp-5);
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-1);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: 
    background var(--t-fast) var(--ease-out),
    transform var(--t-fast) var(--ease-out),
    box-shadow var(--t-fast) var(--ease-out);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active {
  transform: scale(0.97);
  transition-duration: 60ms;
}

.btn-primary {
  background: var(--brand-500);
  color: var(--text-on-brand);
  box-shadow: var(--shadow-1);
}
.btn-primary:hover { background: var(--brand-600); box-shadow: var(--shadow-2); }
.btn-primary:active { background: var(--brand-700); }

.btn-secondary {
  background: var(--brand-100);
  color: var(--brand-700);
}
.btn-secondary:hover { background: var(--brand-200); }

[data-theme="dark"] .btn-secondary {
  background: var(--brand-50);
  color: var(--brand-300);
}

.btn-ghost {
  background: transparent;
  color: var(--text-1);
}
.btn-ghost:hover { background: var(--bg-subtle); }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: var(--danger-deep); }

/* === 输入框 === */
.input, input[type="text"], input[type="search"], input[type="email"], input[type="password"], textarea {
  display: block;
  width: 100%;
  height: var(--h-input);
  padding: 0 var(--sp-4);
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  background: var(--bg-card);
  color: var(--text-1);
  font-size: var(--fs-md);
  font-family: inherit;
  transition: 
    border-color var(--t-fast) var(--ease-out),
    box-shadow var(--t-fast) var(--ease-out),
    background var(--t-fast) var(--ease-out);
  outline: none;
  -webkit-appearance: none;
}
.input:focus, input:focus, textarea:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(61, 90, 254, 0.15);
}
.input::placeholder, input::placeholder, textarea::placeholder {
  color: var(--text-4);
}
textarea {
  height: auto;
  padding: var(--sp-3) var(--sp-4);
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

/* === 头像 — 6 色渐变按 username hash === */
.avatar {
  width: 44px; height: 44px;
  border-radius: var(--r-full);
  background: var(--avatar-grad-1);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: var(--fw-semibold);
  flex-shrink: 0; user-select: none;
  position: relative; overflow: hidden;
  letter-spacing: 0;
  text-transform: uppercase;
  box-shadow: var(--shadow-1);
  transition: transform var(--t-fast) var(--ease-spring);
}
.avatar[data-h="0"] { background: var(--avatar-grad-1); }
.avatar[data-h="1"] { background: var(--avatar-grad-2); }
.avatar[data-h="2"] { background: var(--avatar-grad-3); }
.avatar[data-h="3"] { background: var(--avatar-grad-4); }
.avatar[data-h="4"] { background: var(--avatar-grad-5); }
.avatar[data-h="5"] { background: var(--avatar-grad-6); }

.avatar.sm { width: 32px; height: 32px; font-size: 13px; }
.avatar.md { width: 40px; height: 40px; font-size: 15px; }
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }
.avatar.xl { width: 80px; height: 80px; font-size: 28px; }

@media (hover: hover) {
  .avatar:hover { transform: scale(1.05); }
}

/* === 列表项 — 微信/iMessage 风, 节奏一致 === */
.list-item {
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: 60px;    /* 72px */
  padding: 10px 16px;
  background: transparent;
  cursor: pointer;
  position: relative;
  overflow: hidden;            /* ★ fix66dao: 兜底 (swipe 时截掉边缘) */
  transition: background var(--t-fast) var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.list-item:hover { background: var(--bg-subtle); }
.list-item:active { background: var(--border-1); }

.list-item-main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}

.list-item-title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  color: var(--text-1);
  line-height: 1.4;                  /* ★ fix66dao: 兜底 (line-height 防止上下裁切) */
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  letter-spacing: -0.01em;
}

.list-item-preview {
  font-size: var(--fs-sm);
  color: var(--text-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  line-height: 1.4;
}

.list-item-meta {
  font-size: var(--fs-xs);
  color: var(--text-3);
  flex-shrink: 0;
}

.list-item-extra {
  display: flex; flex-direction: column;
  align-items: flex-end; gap: var(--sp-1);
  flex-shrink: 0;
}

/* === badge — 红圆点 (iMessage/微信 标志) === */
.badge {
  display: inline-flex;
  align-items: center; justify-content: center;
  min-width: 20px; height: 20px;
  padding: 0 6px;
  background: var(--danger);
  color: white;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  border-radius: var(--r-full);
  letter-spacing: 0;
}
.badge.dot {
  width: 8px; height: 8px;
  min-width: 8px;
  padding: 0;
}

/* === 卡片 — iOS 风, 多层阴影 === */
.card {
  background: var(--bg-card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: var(--sp-4);
  transition: box-shadow var(--t-fast) var(--ease-out);
}
.card:hover { box-shadow: var(--shadow-2); }

/* === 分隔线 === */
.divider {
  height: 1px;
  background: var(--border-1);
  margin: var(--sp-3) 0;
  border: 0;
}

/* === 顶栏 === */
/* design-system 不重定义 .app-header / .app-title — 让 app.css 的 fixed 版本生效
   (fixed 在 flexbox 内才能可靠固定; sticky 会失效)
   只补: app.css 没定义的 font / letter-spacing 增强 */
.app-header {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  height: calc(44px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: var(--sp-4);
  padding-right: var(--sp-4);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-1);
  z-index: 100;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}
/* app-title 补 letter-spacing */
.app-title { letter-spacing: -0.02em; }

/* === tabbar === */
/* design-system 不重定义 position / max-width / z-index — 让 app.css 的 fixed 版本生效 */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  height: calc(49px + env(safe-area-inset-bottom, 0px));
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border-1);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 100;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}
/* tab-item - design-system 只补: 字重 / 触控反馈 / 过渡曲线 */
.tab-item {
  font-weight: var(--fw-medium);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color var(--t-fast) var(--ease-out);
}
.tab-item:active {
  opacity: 0.6;
  transition-duration: 60ms;
}

/* === modal === */
.modal-mask {
  position: fixed; inset: 0;
  background: var(--bg-overlay);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-4);
  z-index: var(--z-modal-mask);
  animation: modalMaskIn var(--t-base) var(--ease-out);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.modal-sheet {
  background: var(--bg-card);
  border-radius: var(--r-2xl);
  max-width: 420px;
  width: 100%;
  max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-popover);
  animation: modalIn var(--t-slow) var(--ease-spring);
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-1);
  flex-shrink: 0;
}
.modal-title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.01em;
}
.modal-body {
  flex: 1; overflow-y: auto;
  padding: var(--sp-5);
}

.modal-desc {
  padding: 0 var(--sp-5);
  margin-top: -8px;
  margin-bottom: var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--text-3);
  line-height: 1.4;
}

/* modal-actions = modal-footer 别名 (向后兼容) */
.modal-actions {
  display: flex; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5) var(--sp-4);
  border-top: 1px solid var(--border-1);
  flex-shrink: 0;
}
.modal-actions .btn { flex: 1; }

/* 标准 modal-sheet 宽度变体 */
.modal-sheet { max-width: 420px; }
.modal-sheet.size-sm { max-width: 340px; }
.modal-sheet.size-md { max-width: 420px; }
.modal-sheet.size-lg { max-width: 480px; }
.modal-sheet.size-xl { max-width: 560px; }

/* btn-text = btn-ghost 别名 */
.btn-text {
  background: transparent;
  color: var(--brand-500);
  height: var(--h-btn);
  padding: 0 var(--sp-5);
  border: none;
  border-radius: var(--r-sm);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease-out);
}
.btn-text:hover { background: var(--bg-subtle); }

.modal-footer {
  display: flex; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5) var(--sp-4);
  border-top: 1px solid var(--border-1);
  flex-shrink: 0;
}
.modal-footer .btn { flex: 1; }

@keyframes modalMaskIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* === Toast — 上滑进入, 弹簧曲线 === */
.toast {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  padding: var(--sp-3) var(--sp-5);
  background: rgba(0, 0, 0, 0.85);
  color: white;
  border-radius: var(--r-md);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  box-shadow: var(--shadow-3);
  z-index: var(--z-toast);
  animation: toastIn var(--t-slow) var(--ease-spring);
  max-width: 80vw;
  text-align: center;
  backdrop-filter: blur(8px);
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 12px)) scale(0.95); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* === empty state — 优雅留白 === */
/* empty-state - design-system 补: color / opacity (app.css 已有 layout) */
.empty-state { color: var(--text-3); }
.empty-state-icon { background: var(--bg-subtle); opacity: 0.5; }
.empty-state-title { font-weight: var(--fw-semibold); }
.empty-state-desc { line-height: 1.5; max-width: 280px; }

/* === 滚动条 — 极细 === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-3);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }
@media (max-width: 767px) {
  ::-webkit-scrollbar { display: none; }
}

/* === 焦点环 === */
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* === 减少动效 === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
 * modal 辅助类
 * ============================================================ */
.modal-header.modal-header-center { justify-content: center; position: relative; }
.modal-header.modal-header-center .modal-close {
  position: absolute;
  right: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
}
.modal-sheet.text-center { text-align: center; }
.modal-sheet.text-center .modal-body { text-align: left; /* 内部仍左对齐 */ }

/* 好友验证问题 modal */
.questions-list {
  display: flex; flex-direction: column; gap: var(--sp-3);
  max-height: 50vh;
  overflow-y: auto;
}
.question-item {
  display: flex; flex-direction: column; gap: var(--sp-2);
}
.question-item input { width: 100%; }

.groups-list {
  display: flex; flex-direction: column;
  gap: var(--sp-1);
  max-height: 50vh;
  overflow-y: auto;
}

.form-stack {
  padding: var(--sp-4);
  display: flex; flex-direction: column;
  gap: var(--sp-3);
}

.mx-auto { margin-left: auto; margin-right: auto; }
.mt-3 { margin-top: var(--sp-3); }
.qr-name { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.qr-handle { font-size: var(--fs-sm); color: var(--text-3); margin: var(--sp-2) 0 var(--sp-3); }
.qr-payload {
  padding: var(--sp-3);
  background: var(--bg-subtle);
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-size: 11px;
  word-break: break-all;
  line-height: 1.4;
}
.qr-hint { font-size: var(--fs-xs); color: var(--text-3); margin-top: var(--sp-3); }

.flex-1 { flex: 1; }

.lang-option {
  display: block; width: 100%;
  padding: 12px 16px;
  text-align: left;
  background: transparent;
  border: 1px solid var(--border-1);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-2);
  cursor: pointer;
  font-size: var(--fs-md);
  color: var(--text-1);
  transition: background var(--t-fast) var(--ease-out);
  font-family: inherit;
}
.lang-option:hover { background: var(--bg-subtle); }
.lang-option-active {
  background: var(--brand-50);
  border-color: var(--brand-200);
}
[data-theme="dark"] .lang-option-active {
  background: var(--brand-50);
  border-color: var(--brand-200);
}

.input-field-textarea { align-items: flex-start; padding: 10px var(--sp-3); }
.input-field-textarea-input {
  flex: 1; min-height: 60px;
  padding: 4px 0;
  resize: none; background: transparent;
  border: none; outline: none;
  font-size: var(--fs-md);
  font-family: inherit;
  color: var(--text-1);
}
.list-item-extra-actions { display: flex; gap: var(--sp-1); }
.empty-state-pad { padding: var(--sp-7) var(--sp-4); }
.empty-state-pad-lg { padding: var(--sp-8) var(--sp-4); }
.icon-18 { width: 18px; height: 18px; opacity: 0.5; }
.icon-36 { width: 36px; height: 36px; opacity: 0.4; }
.icon-16 { width: 16px; height: 16px; opacity: 0.4; }
.muted { opacity: 0.5; }

.search-result-item {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border-1);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease-out);
}
.search-result-item:hover { background: var(--bg-subtle); }
.search-result-sender {
  font-weight: var(--fw-medium);
  color: var(--text-1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.search-result-preview {
  font-size: var(--fs-sm);
  color: var(--text-3);
  margin: 4px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.search-result-time {
  font-size: var(--fs-xs);
  color: var(--text-4);
}
.unread-dot { background: var(--danger); }
.muted-bell { color: var(--text-4); }
.icon-14 { width: 14px; height: 14px; opacity: 0.4; }

.remark-current { font-size: var(--fs-xs); color: var(--text-3); margin-top: -4px; }
.remark-actions { display: flex; gap: var(--sp-2); }

.i18n-list { padding: var(--sp-4); }

.icon-16 { width: 16px; height: 16px; opacity: 0.4; }
.icon-16-mid { width: 16px; height: 16px; opacity: 0.7; }
.icon-18 { width: 18px; height: 18px; opacity: 0.5; }
.icon-36 { width: 36px; height: 36px; opacity: 0.4; }

/* avatar 内的 img 覆盖 */
.avatar > img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.icon-20-mid { width: 20px; height: 20px; opacity: 0.6; }
.icon-20-invert { width: 20px; height: 20px; filter: invert(1); }
.icon-24 { width: 24px; height: 24px; }

/* ============================================================
 * 组件辅助 utility
 * ============================================================ */
.text-center { text-align: center; }

.modal-body.modal-body-flush { padding: 0; }

.select-native {
  flex: 1; height: 100%;
  background: transparent;
  border: none; outline: none;
  font-size: var(--fs-md);
  font-family: inherit;
  color: var(--text-1);
}

.avatar-xs { width: 18px; height: 18px; font-size: 9px; border: 1.5px solid var(--bg-card); }
.avatar-md { width: 36px; height: 36px; font-size: 14px; }
.avatar-overlap { margin-right: -4px; }
.avatar-current { background: linear-gradient(135deg, #10b981, #059669) !important; color: white !important; }
.avatar-muted { background: var(--bg-subtle) !important; color: var(--text-3) !important; }

.comment-input {
  width: 100%; min-height: 80px;
  border: 1px solid var(--border-1);
  border-radius: var(--r-md);
  padding: var(--sp-2);
  font-size: var(--fs-sm);
  font-family: inherit;
  resize: vertical;
  background: var(--bg-card);
  color: var(--text-1);
}
.hidden-input { display: none; }

.empty-state-pad-xl { padding: var(--sp-9) var(--sp-4); }

.icon-20-smile { width: 20px; height: 20px; opacity: 0.55; }
.icon-14.icon-vam { vertical-align: -2px; }

/* 推送偏好 */
.push-loading { text-align: center; color: var(--text-2); }
.push-row { display: flex; align-items: center; gap: var(--sp-2); }
.push-row-gap { gap: var(--sp-2); }
.push-row-border { padding-top: var(--sp-2); border-top: 1px solid var(--border-1); }
.push-sub-status { font-weight: var(--fw-bold); }
.push-sub-status-on { color: var(--success); }
.push-sub-status-off { color: var(--text-2); }
.push-label { display: block; margin-bottom: var(--sp-1); }
.push-textarea {
  width: 100%; resize: vertical;
  font-family: var(--font-mono);
  border: 1px solid var(--border-1);
  border-radius: var(--r-md);
  padding: var(--sp-2);
  font-size: var(--fs-sm);
  background: var(--bg-card);
  color: var(--text-1);
}
.push-footer-note {
  font-size: var(--fs-xs);
  color: var(--text-3);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--border-1);
}

/* 聊天信息 modal */
.chat-info-name { font-size: var(--fs-lg); font-weight: var(--fw-semibold); margin-bottom: 4px; }
.chat-info-handle { font-size: var(--fs-sm); color: var(--text-3); margin-bottom: var(--sp-4); }
.chat-info-signature {
  font-size: var(--fs-sm);
  color: var(--text-2);
  padding: var(--sp-3);
  background: var(--bg-subtle);
  border-radius: var(--r-md);
}

/* 更多面板 (4 列 grid) */
.more-panel-grid {
  padding: var(--sp-4);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-4);
  text-align: center;
}
.more-panel-footer {
  text-align: center;
  padding: var(--sp-2) var(--sp-4) var(--sp-4);
  color: var(--text-3);
  font-size: var(--fs-xs);
}

.avatar-img-full {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.moments-image-loading { display: none; background: var(--bg-subtle); }

/* ============================================================
 * Pull-to-Refresh — 下拉刷新指示器
 * ============================================================ */
.ptr-indicator {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 50px;
  display: flex; align-items: center; justify-content: center;
  gap: var(--sp-2);
  color: var(--text-3);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  pointer-events: none;
  transform: translateY(-50px);
  opacity: 0;
  transition: transform 200ms var(--ease-out), opacity 200ms var(--ease-out);
  z-index: 10;
}
.ptr-spinner {
  width: 22px; height: 22px;   /* ★ fix62dao: 18 → 22 更醒目 */
  border: 2.5px solid var(--border-3);
  border-top-color: var(--brand-500);
  border-radius: 50%;
  animation: ptr-spin 700ms linear infinite;
}
.ptr-loading .ptr-spinner,
.ptr-ready .ptr-spinner {
  animation: ptr-spin 700ms linear infinite;
}
@keyframes ptr-spin {
  to { transform: rotate(360deg); }
}

