/* ============================================
 * common.css - 全局样式 + 微信风格变量
 * 即时聊天系统 H5 前端公共样式
 * ============================================ */

/* CSS 变量定义 */
:root {
  /* 微信主色 */
  --wx-green: #07C160;
  --wx-green-press: #06AD56;
  --wx-green-light: #95EC69;
  --wx-bg: #EDEDED;
  --wx-nav: #3B3B3B;
  --wx-nav-light: #2E2E2E;

  /* 文字颜色 */
  --wx-text-primary: #191919;
  --wx-text-secondary: #7F7F7F;
  --wx-text-tertiary: #B2B2B2;
  --wx-text-white: #FFFFFF;
  --wx-text-link: #576B95;

  /* 背景色 */
  --wx-bg-white: #FFFFFF;
  --wx-bg-gray: #F7F7F7;
  --wx-bg-mask: rgba(0, 0, 0, 0.6);
  --wx-bg-hover: #ECECEC;

  /* 边框色 */
  --wx-border: #E5E5E5;
  --wx-border-light: #EEEEEE;

  /* 红点 */
  --wx-red: #FA5151;
  --wx-badge: #FA5151;

  /* 字体大小 */
  --wx-font-xs: 11px;
  --wx-font-sm: 12px;
  --wx-font-md: 14px;
  --wx-font-lg: 15px;
  --wx-font-xl: 17px;
  --wx-font-xxl: 20px;

  /* 圆角 */
  --wx-radius-sm: 4px;
  --wx-radius-md: 8px;
  --wx-radius-lg: 12px;
  --wx-radius-circle: 50%;

  /* 间距 */
  --wx-gap-xs: 4px;
  --wx-gap-sm: 8px;
  --wx-gap-md: 12px;
  --wx-gap-lg: 16px;
  --wx-gap-xl: 20px;

  /* 导航栏高度 */
  --wx-nav-height: 44px;
  --wx-tab-height: 50px;

  /* 安全区 */
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

/* ============================================
 * 基础重置
 * ============================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Helvetica, sans-serif;
  font-size: var(--wx-font-md);
  color: var(--wx-text-primary);
  background-color: var(--wx-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-overflow-scrolling: touch;
  overflow-x: hidden;
}

a {
  text-decoration: none;
  color: inherit;
}

input, textarea, button {
  font-family: inherit;
  font-size: inherit;
  border: none;
  outline: none;
  background: none;
}

ul, ol {
  list-style: none;
}

img {
  display: block;
  max-width: 100%;
}

/* ============================================
 * 通用 flex 布局类
 * ============================================ */
.flex {
  display: flex;
}

.flex-inline {
  display: inline-flex;
}

.flex-col {
  display: flex;
  flex-direction: column;
}

.flex-row {
  display: flex;
  flex-direction: row;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flex-around {
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.flex-start {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.flex-end {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.flex-wrap {
  flex-wrap: wrap;
}

.flex-1 {
  flex: 1;
  min-width: 0;
}

.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }

/* ============================================
 * 文字工具类
 * ============================================ */
.text-xs { font-size: var(--wx-font-xs); }
.text-sm { font-size: var(--wx-font-sm); }
.text-md { font-size: var(--wx-font-md); }
.text-lg { font-size: var(--wx-font-lg); }
.text-xl { font-size: var(--wx-font-xl); }
.text-xxl { font-size: var(--wx-font-xxl); }

.text-gray { color: var(--wx-text-secondary); }
.text-light { color: var(--wx-text-tertiary); }
.text-green { color: var(--wx-green); }
.text-white { color: var(--wx-text-white); }
.text-red { color: var(--wx-red); }
.text-link { color: var(--wx-text-link); }

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }
.text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.text-ellipsis-2 {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.font-bold { font-weight: 600; }
.font-normal { font-weight: 400; }

/* ============================================
 * 间距工具类
 * ============================================ */
.mt-xs { margin-top: var(--wx-gap-xs); }
.mt-sm { margin-top: var(--wx-gap-sm); }
.mt-md { margin-top: var(--wx-gap-md); }
.mt-lg { margin-top: var(--wx-gap-lg); }
.mb-xs { margin-bottom: var(--wx-gap-xs); }
.mb-sm { margin-bottom: var(--wx-gap-sm); }
.mb-md { margin-bottom: var(--wx-gap-md); }
.mb-lg { margin-bottom: var(--wx-gap-lg); }
.pt-sm { padding-top: var(--wx-gap-sm); }
.pb-sm { padding-bottom: var(--wx-gap-sm); }
.p-md { padding: var(--wx-gap-md); }
.p-lg { padding: var(--wx-gap-lg); }

/* ============================================
 * 1px 边框处理（移动端1px问题）
 * ============================================ */
.border-t {
  position: relative;
}
.border-t::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background-color: var(--wx-border);
  transform: scaleY(0.5);
  transform-origin: 0 0;
}
.border-b {
  position: relative;
}
.border-b::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background-color: var(--wx-border);
  transform: scaleY(0.5);
  transform-origin: 0 100%;
}

/* ============================================
 * 页面整体布局
 * ============================================ */
.page {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background-color: var(--wx-bg);
  overflow: hidden;
}

.page-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ============================================
 * 导航栏（顶部）
 * ============================================ */
.navbar {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
  height: var(--wx-nav-height);
  min-height: var(--wx-nav-height);
  padding-top: var(--safe-top);
  background-color: var(--wx-nav);
  color: var(--wx-text-white);
  font-size: var(--wx-font-xl);
  font-weight: 500;
  flex-shrink: 0;
}

.navbar .nav-title {
  font-size: var(--wx-font-xl);
  font-weight: 500;
}

.navbar .nav-left {
  position: absolute;
  left: var(--wx-gap-sm);
  top: var(--safe-top);
  height: var(--wx-nav-height);
  display: flex;
  align-items: center;
  padding: 0 var(--wx-gap-sm);
  font-size: var(--wx-font-lg);
}

.navbar .nav-right {
  position: absolute;
  right: var(--wx-gap-sm);
  top: var(--safe-top);
  height: var(--wx-nav-height);
  display: flex;
  align-items: center;
  padding: 0 var(--wx-gap-sm);
  font-size: var(--wx-font-lg);
}

.navbar .nav-left:active,
.navbar .nav-right:active {
  opacity: 0.6;
}

.navbar .nav-icon {
  font-size: 22px;
  width: 28px;
  text-align: center;
}

/* 绿色导航栏（部分页面使用） */
.navbar-green {
  background-color: var(--wx-green);
}

/* ============================================
 * 底部 Tab 栏
 * ============================================ */
.tabbar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: 100%;
  height: var(--wx-tab-height);
  min-height: var(--wx-tab-height);
  padding-bottom: var(--safe-bottom);
  background-color: var(--wx-bg-white);
  border-top: 1px solid var(--wx-border-light);
  flex-shrink: 0;
}

.tabbar .tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  color: var(--wx-text-secondary);
  font-size: var(--wx-font-xs);
  position: relative;
}

.tabbar .tab-item .tab-icon {
  font-size: 22px;
  line-height: 1;
  margin-bottom: 2px;
}

.tabbar .tab-item .tab-label {
  font-size: var(--wx-font-xs);
}

.tabbar .tab-item.active {
  color: var(--wx-green);
}

.tabbar .tab-item:active {
  opacity: 0.7;
}

.tabbar .tab-item .tab-badge {
  position: absolute;
  top: 2px;
  left: 50%;
  margin-left: 8px;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background-color: #FA5151;
  color: #FFEB3B;
  font-size: 10px;
  font-weight: 600;
  text-align: center;
  z-index: 10;
}

/* ============================================
 * 列表项通用样式
 * ============================================ */
.list-item {
  display: flex;
  align-items: center;
  padding: var(--wx-gap-sm) var(--wx-gap-lg);
  background-color: var(--wx-bg-white);
  position: relative;
  min-height: 48px;
}

.list-item:active {
  background-color: var(--wx-bg-hover);
}

.list-item .item-label {
  flex-shrink: 0;
  font-size: var(--wx-font-md);
  color: var(--wx-text-primary);
}

.list-item .item-value {
  flex: 1;
  text-align: right;
  font-size: var(--wx-font-sm);
  color: var(--wx-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item .item-arrow {
  flex-shrink: 0;
  margin-left: var(--wx-gap-sm);
  color: var(--wx-text-tertiary);
  font-size: var(--wx-font-sm);
}

/* 列表分组标题 */
.list-group-title {
  padding: 6px var(--wx-gap-lg);
  font-size: var(--wx-font-xs);
  color: var(--wx-text-secondary);
  background-color: var(--wx-bg);
}

/* ============================================
 * 头像组件
 * ============================================ */
.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #C9C9C9;
  color: #fff;
  font-size: var(--wx-font-md);
  border-radius: var(--wx-radius-sm);
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-round {
  border-radius: var(--wx-radius-circle);
}

.avatar-sm { width: 32px; height: 32px; font-size: 12px; }
.avatar-md { width: 40px; height: 40px; font-size: var(--wx-font-md); }
.avatar-lg { width: 48px; height: 48px; font-size: var(--wx-font-lg); }
.avatar-xl { width: 64px; height: 64px; font-size: var(--wx-font-xl); }

/* 头像占位 - 根据名字生成背景色 */
.avatar-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

/* ============================================
 * 按钮
 * ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--wx-gap-lg);
  height: 44px;
  border-radius: var(--wx-radius-sm);
  font-size: var(--wx-font-md);
  font-weight: 400;
  text-align: center;
  cursor: pointer;
  transition: opacity 0.1s;
  -webkit-user-select: none;
  user-select: none;
}

.btn:active {
  opacity: 0.7;
}

.btn-primary {
  background-color: var(--wx-green);
  color: var(--wx-text-white);
}

.btn-primary:active {
  background-color: var(--wx-green-press);
}

.btn-default {
  background-color: var(--wx-bg-white);
  color: var(--wx-text-primary);
  border: 1px solid var(--wx-border);
}

.btn-warn {
  background-color: var(--wx-red);
  color: var(--wx-text-white);
}

.btn-disabled {
  background-color: #C9C9C9;
  color: #fff;
  pointer-events: none;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  height: 32px;
  font-size: var(--wx-font-sm);
  padding: 0 var(--wx-gap-md);
}

.btn-lg {
  height: 50px;
  font-size: var(--wx-font-lg);
}

.btn-round {
  border-radius: var(--wx-radius-lg);
}

/* ============================================
 * 输入框
 * ============================================ */
.input-group {
  display: flex;
  align-items: center;
  background-color: var(--wx-bg-white);
  padding: var(--wx-gap-sm) var(--wx-gap-lg);
}

.input-group .input-label {
  flex-shrink: 0;
  width: 80px;
  font-size: var(--wx-font-md);
  color: var(--wx-text-primary);
}

.input-group .input-field {
  flex: 1;
  height: 40px;
  font-size: var(--wx-font-md);
  color: var(--wx-text-primary);
}

.input-field::placeholder {
  color: var(--wx-text-tertiary);
}

.input-row {
  display: flex;
  align-items: center;
  background-color: #fff;
  border-radius: var(--wx-radius-sm);
  padding: 0 var(--wx-gap-md);
  height: 44px;
  margin: var(--wx-gap-sm) var(--wx-gap-lg);
}

.input-row input {
  flex: 1;
  height: 100%;
  font-size: var(--wx-font-md);
}

/* ============================================
 * 未读消息红点
 * ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background-color: #FA5151;
  color: #FFEB3B;
  font-size: 10px;
  font-weight: 600;
  text-align: center;
}

.badge-dot {
  width: 8px;
  height: 8px;
  min-width: 8px;
  border-radius: 50%;
  padding: 0;
}

/* ============================================
 * 蒙层遮罩
 * ============================================ */
.mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--wx-bg-mask);
  z-index: 1000;
  display: none;
}

.mask.show {
  display: block;
}

/* ============================================
 * 弹窗 / ActionSheet
 * ============================================ */
.actionsheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--wx-bg);
  z-index: 1001;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  padding-bottom: var(--safe-bottom);
}

.actionsheet.show {
  transform: translateY(0);
}

.actionsheet-item {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  background-color: #fff;
  font-size: var(--wx-font-lg);
  color: var(--wx-text-primary);
  border-bottom: 1px solid var(--wx-border-light);
}

.actionsheet-item:active {
  background-color: var(--wx-bg-hover);
}

.actionsheet-cancel {
  margin-top: 8px;
}

.actionsheet-gap {
  height: 8px;
  background-color: var(--wx-bg);
}

/* ============================================
 * Toast 提示
 * ============================================ */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--wx-radius-sm);
  font-size: var(--wx-font-sm);
  z-index: 2000;
  max-width: 80%;
  text-align: center;
  display: none;
}

.toast.show {
  display: block;
}

/* ============================================
 * Loading 加载
 * ============================================ */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--wx-gap-md);
  color: var(--wx-text-secondary);
  font-size: var(--wx-font-sm);
}

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--wx-border);
  border-top-color: var(--wx-green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: var(--wx-gap-sm);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================
 * 空状态
 * ============================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px var(--wx-gap-lg);
  color: var(--wx-text-tertiary);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: var(--wx-gap-md);
}

.empty-state .empty-text {
  font-size: var(--wx-font-sm);
}

/* ============================================
 * 开关 Switch
 * ============================================ */
.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  border-radius: 13px;
  transition: 0.3s;
}

.switch-slider::before {
  content: '';
  position: absolute;
  height: 22px;
  width: 22px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: 0.3s;
}

.switch input:checked + .switch-slider {
  background-color: var(--wx-green);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(20px);
}

/* ============================================
 * 红点提示（右上角小圆点）
 * ============================================ */
.dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background-color: var(--wx-red);
  border-radius: 50%;
}

/* ============================================
 * 卡片分组
 * ============================================ */
.card {
  background-color: var(--wx-bg-white);
  border-radius: var(--wx-radius-sm);
  overflow: hidden;
}

.card-group {
  margin: var(--wx-gap-md) 0;
}

.card-group-title {
  padding: var(--wx-gap-sm) var(--wx-gap-lg);
  font-size: var(--wx-font-xs);
  color: var(--wx-text-secondary);
}

/* ============================================
 * 分割线
 * ============================================ */
.divider {
  height: 8px;
  background-color: var(--wx-bg);
}

.divider-line {
  height: 1px;
  background-color: var(--wx-border);
  transform: scaleY(0.5);
  margin: 0 var(--wx-gap-lg);
}

/* ============================================
 * 安全区域
 * ============================================ */
.safe-bottom {
  padding-bottom: var(--safe-bottom);
}

.safe-top {
  padding-top: var(--safe-top);
}

/* ============================================
 * 滚动隐藏滚动条
 * ============================================ */
.scroll-hidden::-webkit-scrollbar {
  display: none;
}
.scroll-hidden {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

/* ============================================
 * 隐藏 / 显示
 * ============================================ */
.hidden { display: none !important; }
.visible { display: block; }

/* ============================================
 * 定位
 * ============================================ */
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }

/* ============================================
 * 宽高
 * ============================================ */
.w-full { width: 100%; }
.h-full { height: 100%; }

/* ============================================
 * 滑块验证组件
 * ============================================ */
.slider-verify {
  position: relative;
  width: 100%;
  height: 40px;
  background-color: #E8E8E8;
  border-radius: var(--wx-radius-sm);
  overflow: hidden;
}

.slider-track {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background-color: var(--wx-green-light);
  opacity: 0.5;
  width: 0;
  transition: width 0.1s;
}

.slider-text {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--wx-font-sm);
  color: var(--wx-text-secondary);
  pointer-events: none;
}

.slider-btn {
  position: absolute;
  top: 0;
  left: 0;
  width: 40px;
  height: 40px;
  background-color: #fff;
  border: 1px solid var(--wx-border);
  border-radius: var(--wx-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--wx-font-lg);
  color: var(--wx-text-secondary);
  cursor: pointer;
  z-index: 2;
}

.slider-btn.success {
  background-color: var(--wx-green);
  color: #fff;
  border-color: var(--wx-green);
}
