/* ============================================================
   通用组件：按钮 / 标签 / 头像 / 段位 / 卡片 / 表单 /
             弹窗 / 菜单 / Toast / 开关 / 进度
   ============================================================ */

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 16px;
  border-radius: 9px; font-size: 13px; font-weight: 500;
  border: 1px solid transparent;
  transition: background-color .16s, border-color .16s, color .16s, transform .12s, box-shadow .16s;
  white-space: nowrap; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent-active); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-3); border-color: var(--faint); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-soft { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.btn-soft:hover { background: rgba(140,47,57,.14); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #9c4141; }
.btn-gold { background: linear-gradient(135deg, #b08d57, #8f7142); color: #fff; }
.btn-sm { height: 28px; padding: 0 11px; font-size: 12px; border-radius: 7px; }
.btn-lg { height: 42px; padding: 0 22px; font-size: 14.5px; border-radius: 11px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ---------- 标签 chip ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px;
  border-radius: 6px; font-size: 11px; font-weight: 500;
  background: var(--surface-3); color: var(--muted);
  white-space: nowrap;
}
.tag.accent { background: var(--accent-soft); color: var(--accent); }
.tag.gold { background: var(--gold-soft); color: var(--gold); }
.tag.success { background: var(--success-soft); color: var(--success); }
.tag.info { background: var(--info-soft); color: var(--info); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.warning { background: var(--warning-soft); color: var(--warning); }
.tag .icon { width: 12px; height: 12px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 5px; }

/* ---------- 头像（首字母材质化，避免幼稚感） ---------- */
.avatar {
  --h: 38px;
  width: var(--h); height: var(--h); border-radius: 50%;
  display: grid; place-items: center;
  font-size: calc(var(--h) * .36); font-weight: 600; color: #fff;
  flex: none; user-select: none; position: relative;
  letter-spacing: 0;
  text-shadow: 0 1px 2px rgba(0,0,0,.18);
}
.avatar.sm { --h: 28px; font-size: 11px; }
.avatar.md { --h: 44px; }
.avatar.lg { --h: 56px; }
.avatar.xl { --h: 76px; font-size: 28px; }
.avatar.xxl { --h: 96px; font-size: 36px; }
.avatar.square { border-radius: 12px; }

/* 在线状态点 */
.avatar .presence {
  position: absolute; right: -1px; bottom: -1px;
  width: 11px; height: 11px; border-radius: 50%;
  border: 2.5px solid var(--surface);
  background: var(--faint);
}
.avatar .presence.online { background: var(--success); }
.avatar .presence.room { background: var(--accent); }
.avatar .presence.away { background: var(--warning); }

/* 头像框（装扮） */
.avatar.framed::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  pointer-events: none;
}
.avatar.frame-gold.framed::after { background: conic-gradient(from 40deg, #d9bc7e, #8f7142, #f0dda9, #9c7e46, #d9bc7e); -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 0); mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 0); }
.avatar.frame-hex.framed::after { border: 2px solid var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); inset: -7px; }
.avatar.frame-neon.framed::after { border: 2px solid #5fb4c9; box-shadow: 0 0 10px rgba(95,180,201,.55); }
.avatar.frame-silver.framed::after { border: 2px solid #b9c0ca; }
.avatar.frame-vip.framed::after { border: 2px dashed var(--gold); animation: spin 8s linear infinite; }

/* 小贵族标 */
.noble-flag {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 700; color: var(--gold);
  background: var(--gold-soft); border-radius: 5px; padding: 0 5px; height: 19px;
}
.noble-flag .icon { width: 11px; height: 11px; }
.vip-flag {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 700; color: var(--accent);
  background: var(--accent-soft); border-radius: 5px; padding: 0 5px; height: 19px;
}

/* ---------- 段位徽章 ---------- */
.rank-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600;
}
.rank-mark {
  width: 16px; height: 16px; flex: none;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}
.rank-badge.t9 .rank-mark {
  background: linear-gradient(135deg, #f0dd9f, #c9a34f 60%, #8f6f35);
}

/* 位置标 */
.pos-tag {
  width: 20px; height: 20px; border-radius: 6px;
  display: inline-grid; place-items: center;
  background: var(--surface-3); color: var(--muted);
}
.pos-tag.on { background: var(--accent-soft); color: var(--accent); }
.pos-tag .icon { width: 12px; height: 12px; }
.pos-tag.filled { background: var(--success-soft); color: var(--success); }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  transition: border-color .18s, box-shadow .18s, transform .2s var(--ease);
}
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card-pad { padding: 16px; }

/* 分割线 */
hr.hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.hr-v { width: 1px; background: var(--border); align-self: stretch; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 15px; }
.field > label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-2); margin-bottom: 7px; }
.field .hint { font-size: 11.5px; color: var(--faint); margin-top: 5px; }
.input, .select, .textarea {
  width: 100%; height: 37px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: 9px;
  background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.6; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: var(--ring); }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.select { appearance: none; padding-right: 32px; background-image: none; cursor: pointer; }
.select-wrap { position: relative; }
.select-wrap::after {
  content: ""; position: absolute; right: 12px; top: 50%;
  width: 8px; height: 8px; border-right: 1.5px solid var(--faint); border-bottom: 1.5px solid var(--faint);
  transform: translateY(-70%) rotate(45deg); pointer-events: none;
}
.input-suffix-wrap { position: relative; }
.input-suffix-wrap .input { padding-right: 74px; }
.input-suffix { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* 单选 chip 组（筛选/表单选择） */
.choice-group { display: flex; flex-wrap: wrap; gap: 7px; }
.choice {
  height: 30px; padding: 0 13px;
  border-radius: 8px; font-size: 12.5px;
  border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text-2);
  display: inline-flex; align-items: center; gap: 5px;
  cursor: pointer; transition: all .15s; user-select: none;
}
.choice:hover { border-color: var(--faint); }
.choice.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.choice.on.gold { border-color: var(--gold); background: var(--gold-soft); color: var(--gold); }

/* 开关 */
.switch { position: relative; width: 38px; height: 22px; flex: none; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .sl {
  position: absolute; inset: 0; border-radius: 99px;
  background: var(--border-strong); transition: .2s;
}
.switch .sl::before {
  content: ""; position: absolute; left: 3px; top: 3px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: .22s var(--ease-spring);
}
.switch input:checked + .sl { background: var(--accent); }
.switch input:checked + .sl::before { transform: translateX(16px); }
.switch input:disabled + .sl { opacity: .45; cursor: not-allowed; }

.setting-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 2px; border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: 0; }
.setting-row .sr-text { flex: 1; }
.setting-row .sr-title { font-size: 13.5px; font-weight: 500; display: flex; align-items: center; gap: 7px; }
.setting-row .sr-sub { font-size: 11.5px; color: var(--faint); margin-top: 2px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab {
  position: relative; height: 40px; padding: 0 16px;
  font-size: 13.5px; color: var(--muted); font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  transition: color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); font-weight: 600; }
.tab.active::after {
  content: ""; position: absolute; bottom: -1px; left: 14px; right: 14px; height: 2px;
  border-radius: 2px; background: var(--accent);
}
.tab .count { font-size: 11px; color: var(--faint); font-weight: 500; }
.tab.active .count { color: var(--accent); }

/* 胶囊分段控件 */
.segmented { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button {
  height: 28px; padding: 0 14px; border-radius: 7px; font-size: 12.5px;
  color: var(--muted); font-weight: 500; transition: all .15s;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); font-weight: 600; }

/* ---------- 弹窗 ---------- */
.modal-scrim {
  position: fixed; inset: 0; z-index: 200;
  background: var(--scrim);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  display: grid; place-items: center; padding: 28px;
  animation: fadeIn .2s var(--ease);
}
.modal {
  width: 540px; max-width: 100%; max-height: 86vh;
  background: var(--elevated); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  animation: modalIn .26s var(--ease-spring);
  overflow: hidden;
}
.modal.wide { width: 760px; }
.modal.narrow { width: 420px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 17px 20px; border-bottom: 1px solid var(--border); flex: none;
}
.modal-head h3 { font-size: 15.5px; }
.modal-head .mh-sub { font-size: 11.5px; color: var(--faint); margin-top: 2px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border);
  background: var(--surface-2); flex: none;
}

/* ---------- 右键/下拉菜单 ---------- */
.menu {
  position: fixed; z-index: 300; min-width: 172px;
  background: var(--elevated); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-md);
  padding: 6px; animation: menuIn .16s var(--ease);
}
@keyframes menuIn { from { opacity: 0; transform: scale(.96) translateY(-4px); } to { opacity: 1; transform: none; } }
.menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; height: 36px; padding: 0 11px;
  border-radius: 8px; font-size: 13px; color: var(--text-2);
  text-align: left;
}
.menu-item:hover { background: var(--surface-3); color: var(--text); }
.menu-item .icon { width: 16px; height: 16px; color: var(--muted); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger .icon { color: var(--danger); }
.menu-item:disabled { opacity: .45; cursor: not-allowed; }
.menu-sep { height: 1px; background: var(--border); margin: 5px 8px; }
.menu-label { font-size: 11px; color: var(--faint); padding: 7px 11px 3px; }

/* ---------- Toast ---------- */
.toast-root {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 500; display: flex; flex-direction: column; gap: 9px; align-items: center;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 9px;
  background: var(--elevated); border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  border-radius: 11px; padding: 11px 17px;
  font-size: 13px; max-width: 420px;
  animation: toastIn .3s var(--ease-spring);
}
.toast.leaving { animation: toastOut .25s var(--ease) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px) scale(.98); } }
.toast .icon { width: 17px; height: 17px; }
.toast.success .icon { color: var(--success); }
.toast.error .icon { color: var(--danger); }
.toast.warning .icon { color: var(--warning); }

/* ---------- 进度条 ---------- */
.progress { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .4s var(--ease); }
.progress.gold > i { background: linear-gradient(90deg, #c9a668, #a17f47); }

/* 徽标数 */
.dot-badge {
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 9px;
  background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700;
  display: inline-grid; place-items: center;
}

/* 列表行 */
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 10px;
  transition: background-color .15s; cursor: pointer;
}
.list-row:hover { background: var(--surface-3); }
.list-row .lr-main { flex: 1; min-width: 0; }
.list-row .lr-title { font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.list-row .lr-sub { font-size: 11.5px; color: var(--faint); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .lr-act { flex: none; }

/* 下拉面板通用 */
.pop-panel {
  position: absolute; z-index: 80;
  background: var(--elevated); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  padding: 8px; animation: menuIn .16s var(--ease);
}

/* 简单骨架/加载 */
.loading-dots { display: inline-flex; gap: 4px; }
.loading-dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: pulse 1s infinite; }
.loading-dots i:nth-child(2) { animation-delay: .18s; }
.loading-dots i:nth-child(3) { animation-delay: .36s; }

/* 统计数字块 */
.stat-block { text-align: center; padding: 4px 0; }
.stat-block .sb-num { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-block .sb-label { font-size: 11px; color: var(--faint); margin-top: 2px; }
.stat-block + .stat-block { border-left: 1px solid var(--border); }
