/* ============================================================
   components.css —— 通用组件：按钮/卡片/徽章/角标/弹窗/toast/
   骨架屏/空态/顶部栏/底部导航/贴纸占位
   所有色值引用 tokens.css 变量，禁止硬编码
   ============================================================ */

/* ---------- 按钮（pill 圆角，基座一致） ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 22px;
  border-radius: var(--radius-pill);
  font-size: var(--text-16);
  font-weight: 600;
  line-height: 1.4;
  transition: transform 0.15s var(--ease), opacity 0.15s var(--ease), background 0.2s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn--block { display: flex; width: 100%; }
.btn--primary { background: var(--theme-primary); color: #fff; box-shadow: 0 2px 8px color-mix(in srgb, var(--theme-primary) 35%, transparent); }
.btn--primary:disabled { background: var(--line-strong); color: #fff; box-shadow: none; cursor: not-allowed; }
.btn--ghost { background: var(--theme-soft); color: var(--theme-primary-strong); }
.btn--outline { background: transparent; border: 1.5px solid var(--line-strong); color: var(--ink-2); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--sm { padding: 6px 14px; font-size: var(--text-14); }
.btn--lg { padding: 14px 28px; font-size: var(--text-18); }

/* 按钮内 loading 转圈 */
.btn .spin {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 卡片（12px 圆角 + 手绘细边框 + 白底） ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
}

/* ---------- 角色贴纸占位（四小只）
   官方原图待交付（待确认项 #10），此处用主题色圆形贴纸 + 角色名占位。
   ★ 接入官方素材：将 .sticker 改为背景图 <img> 或 background-image，
     颜色/比例/价值观对应关系必须与《公约家族IP形象使用文件》一致，
     严禁 AI 重绘。 ---------- */
.sticker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--theme-sticker-bg);
  border: 2px dashed var(--theme-primary);
  color: var(--theme-primary);
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: var(--text-14);
  user-select: none;
}
.sticker--sm { width: 28px; height: 28px; font-size: var(--text-12); border-width: 1.5px; }
.sticker--lg { width: 64px; height: 64px; font-size: var(--text-22, 22px); }
.sticker--xl { width: 88px; height: 88px; font-size: 30px; }
.sticker--square { border-radius: 26% 74% 62% 38% / 42% 34% 66% 58%; }

/* 头像（默认用角色贴纸，可指定角色） */
.avatar { border-radius: 50%; overflow: hidden; }

/* ---------- 徽章 ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--text-12);
  font-weight: 600;
  line-height: 1.6;
}
.badge--primary { background: var(--theme-soft); color: var(--theme-primary-strong); }
.badge--gray { background: #EFEBE1; color: var(--ink-2); }
.badge--ok { background: #E4F0E6; color: #3E7A52; }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--warn { background: #F7ECD9; color: var(--warn); }

/* ---------- 可见性角标（交互设计 §四：中性灰 + 语义色，不冲突主题色） ---------- */
.vis-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--text-12);
  font-weight: 600;
  line-height: 1.6;
  border: 1px solid transparent;
}
/* V2 仅自己：灰角标 */
.vis-badge--private { background: #EFEBE1; color: #6E6757; border-color: #D8D0BC; }
/* V3 双方可见：橙角标 */
.vis-badge--mutual { background: #FBEDDC; color: #B2601F; border-color: #EFC796; }
/* V4 已隐藏：灰红角标 */
.vis-badge--hidden { background: #F1E4E0; color: #A5483A; border-color: #DDB9AE; }

/* ---------- 顶部栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 52px;
  padding: 0 var(--space-4);
  background: var(--theme-tint);
  border-bottom: 1px solid var(--line);
}
.topbar .back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  font-size: var(--text-20);
  color: var(--ink);
  border-radius: 50%;
}
.topbar .back:active { background: var(--theme-soft); }
.topbar .title {
  flex: 1;
  font-size: var(--text-18);
  font-weight: 700;
  font-family: var(--font-serif);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .action { font-size: var(--text-14); color: var(--theme-primary-strong); font-weight: 600; padding: 6px 8px; }
.topbar .action:disabled { color: var(--ink-3); }

/* 页头主区（版块头部：贴纸 + 名称 + 价值观标签） */
.page-hero {
  background: var(--theme-tint);
  margin: 0 calc(-1 * var(--space-4)) var(--space-4);
  padding: var(--space-5) var(--space-4) var(--space-4);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: var(--space-4);
}
.page-hero .meta { flex: 1; }
.page-hero h1 { font-family: var(--font-serif); font-size: var(--text-24); }
.page-hero .value-tag { color: var(--theme-primary-strong); font-size: var(--text-14); margin-top: 2px; }

/* ---------- 底部导航（4 项，当前页高亮） ---------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--app-max);
  height: 58px;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 40;
}
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: var(--text-12);
  color: var(--ink-3);
  position: relative;
}
.tabbar a .ico { font-size: var(--text-20); line-height: 1; }
.tabbar a.on { color: var(--theme-primary, var(--ink)); font-weight: 600; }
.tabbar a.on .ico { transform: translateY(-1px); }
/* 未读红点 */
.tabbar .dot,
.msg-entry .dot {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: #E0523F;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- 消息入口（首页顶部） ---------- */
.msg-entry {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  font-size: var(--text-20);
  border-radius: 50%;
}
.msg-entry:active { background: var(--theme-soft); }
.msg-entry .dot { position: absolute; top: 2px; right: 0; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: var(--mask);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s var(--ease);
}
.modal-mask--center { align-items: center; padding: var(--space-5); }
.modal {
  width: 100%;
  max-width: var(--app-max);
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding: var(--space-5) var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom));
  max-height: 82vh;
  overflow-y: auto;
  animation: slideUp 0.25s var(--ease);
}
.modal-mask--center .modal { border-radius: var(--radius-card); animation: popIn 0.22s var(--ease); }
.modal h3 { font-family: var(--font-serif); font-size: var(--text-20); margin-bottom: var(--space-3); }
.modal .modal-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 30px; height: 30px;
  font-size: var(--text-18);
  color: var(--ink-3);
  border-radius: 50%;
  z-index: 2;
}
.modal .modal-actions { display: flex; gap: var(--space-3); margin-top: var(--space-5); }
.modal .modal-actions .btn { flex: 1; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes popIn { from { transform: scale(0.9); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  max-width: 78vw;
  padding: 10px 18px;
  background: rgba(45, 40, 30, 0.92);
  color: #fff;
  font-size: var(--text-14);
  border-radius: var(--radius-pill);
  z-index: 200;
  animation: toastIn 0.25s var(--ease);
  text-align: center;
  pointer-events: none;
}
.toast--out { animation: toastOut 0.25s var(--ease) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes toastOut { to { opacity: 0; transform: translate(-50%, 12px); } }

/* ---------- 骨架屏 ---------- */
.skeleton {
  background: linear-gradient(90deg, #EFEAE0 25%, #F7F3EA 50%, #EFEAE0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.skel-card { height: 120px; border-radius: var(--radius-card); }
.skel-line { height: 14px; margin-bottom: var(--space-3); }
.skel-line--sm { height: 10px; width: 60%; }

/* ---------- 空状态（交互设计 §7.1 统一模板：贴纸+主文案+次文案+行动） ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-8) var(--space-5);
  gap: var(--space-2);
}
.empty .sticker { margin-bottom: var(--space-2); }
.empty .main { font-size: var(--text-18); font-weight: 700; font-family: var(--font-serif); }
.empty .sub { font-size: var(--text-14); color: var(--ink-3); }
.empty .btn { margin-top: var(--space-4); }

/* ---------- 列表项通用 ---------- */
.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row .body { flex: 1; min-width: 0; }
.row .title { font-size: var(--text-16); font-weight: 600; }
.row .sub { font-size: var(--text-14); color: var(--ink-2); margin-top: 2px; }
.row .aside { flex-shrink: 0; }

/* 表单 */
.field { margin-bottom: var(--space-5); }
.field label { display: block; font-size: var(--text-14); font-weight: 600; color: var(--ink-2); margin-bottom: var(--space-2); }
.field .req { color: var(--danger); }
.field .hint { font-size: var(--text-12); color: var(--ink-3); margin-top: var(--space-1); }
.input, .textarea, .select {
  width: 100%;
  background: var(--card);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: var(--text-16);
  outline: none;
  transition: border-color 0.2s;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--theme-primary); }
.textarea { min-height: 110px; resize: vertical; line-height: 1.6; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }

/* 手绘边框（金句/签语卡） */
.hand-drawn {
  border: 2px solid var(--theme-primary);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
}
