/* ========================================
   WeChat Lite - 微信轻聊版 样式文件
   移动端APP/PWA 设计
   ======================================== */

/* ---------- CSS变量 ---------- */
:root {
  --primary: #07c160;
  --primary-dark: #06ad56;
  --primary-light: #e8f8ee;
  --danger: #ee0a24;
  --warning: #ff976a;
  --bg: #f7f7f7;
  --bg-card: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #888888;
  --text-muted: #c0c0c0;
  --border: #ebebeb;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.1);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --safe-top: env(safe-area-inset-top, 20px);
  --safe-bottom: env(safe-area-inset-bottom, 16px);
  --tab-height: 56px;
  --header-height: 52px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------- 全局重置 ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.5;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

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

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

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

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* ---------- 主容器 ---------- */
.app-container {
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0,0,0,0.08);
}

/* ---------- 顶部导航 ---------- */
.app-header {
  flex-shrink: 0;
  height: var(--header-height);
  padding-top: var(--safe-top);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 20px;
  padding-right: 20px;
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.header-actions {
  display: flex;
  gap: 18px;
  align-items: center;
}

.header-actions .icon-btn {
  font-size: 22px;
  cursor: pointer;
  transition: transform 0.2s;
  line-height: 1;
}

.header-actions .icon-btn:active {
  transform: scale(0.9);
}

/* ---------- 主内容区 ---------- */
.app-main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: var(--safe-bottom);
  scroll-behavior: smooth;
}

/* ---------- 底部标签栏 ---------- */
.app-tabbar {
  flex-shrink: 0;
  height: var(--tab-height);
  padding-bottom: var(--safe-bottom);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 10;
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s;
  padding: 4px 12px;
  position: relative;
  touch-action: manipulation;
}

.tab-item .tab-icon {
  font-size: 24px;
  line-height: 1;
  transition: transform 0.2s;
}

.tab-item.active {
  color: var(--primary);
}

.tab-item.active .tab-icon {
  transform: scale(1.05);
}

.tab-item:active .tab-icon {
  transform: scale(0.9);
}

.tab-badge {
  position: absolute;
  top: 2px;
  right: 4px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  box-shadow: 0 2px 6px rgba(238,10,36,0.3);
}

/* ---------- 页面容器 ---------- */
.page {
  display: none;
  padding: 0 0 8px 0;
  animation: fadeSlideIn 0.3s ease;
}

.page.active {
  display: block;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- 聊天列表 ---------- */
.chat-list {
  padding: 8px 16px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  border-radius: var(--radius-xs);
  margin: 0 -8px;
  padding-left: 8px;
  padding-right: 8px;
}

.chat-item:last-child {
  border-bottom: none;
}

.chat-item:active {
  background: var(--primary-light);
}

.chat-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #2ecc71);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: white;
  font-weight: 600;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(7,193,96,0.2);
}

.chat-avatar.group {
  background: linear-gradient(135deg, #667eea, #764ba2);
  box-shadow: 0 2px 8px rgba(102,126,234,0.2);
}

.chat-avatar.official {
  background: linear-gradient(135deg, #f093fb, #f5576c);
  box-shadow: 0 2px 8px rgba(245,87,108,0.2);
}

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

.chat-name {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-name .tag {
  font-size: 10px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--primary-light);
  color: var(--primary);
}

.chat-msg {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-meta {
  flex-shrink: 0;
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.chat-time {
  font-size: 12px;
  color: var(--text-muted);
}

.chat-unread {
  background: var(--danger);
  color: white;
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  box-shadow: 0 2px 6px rgba(238,10,36,0.25);
}

/* ---------- 通讯录 ---------- */
.contacts-section-title {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 16px 20px 8px;
  font-weight: 600;
}

.contacts-list {
  padding: 0 16px;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 8px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background 0.15s;
}

.contact-item:active {
  background: var(--primary-light);
}

.contact-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: white;
  font-weight: 600;
  flex-shrink: 0;
}

.contact-name {
  font-size: 15px;
  font-weight: 500;
}

/* ---------- 发现页 ---------- */
.discover-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 20px 16px;
}

.discover-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 8px;
  border-radius: var(--radius);
  background: var(--bg-card);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
}

.discover-item:active {
  transform: scale(0.95);
  box-shadow: var(--shadow-lg);
}

.discover-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: white;
  background: var(--primary);
  box-shadow: 0 4px 12px rgba(7,193,96,0.25);
}

.discover-icon.purple {
  background: linear-gradient(135deg, #667eea, #764ba2);
  box-shadow: 0 4px 12px rgba(102,126,234,0.25);
}

.discover-icon.orange {
  background: linear-gradient(135deg, #f093fb, #f5576c);
  box-shadow: 0 4px 12px rgba(245,87,108,0.25);
}

.discover-icon.blue {
  background: linear-gradient(135deg, #4facfe, #00f2fe);
  box-shadow: 0 4px 12px rgba(79,172,254,0.25);
}

.discover-icon.gold {
  background: linear-gradient(135deg, #f6d365, #fda085);
  box-shadow: 0 4px 12px rgba(246,211,101,0.25);
}

.discover-icon.teal {
  background: linear-gradient(135deg, #43e97b, #38f9d7);
  box-shadow: 0 4px 12px rgba(67,233,123,0.25);
}

.discover-icon.pink {
  background: linear-gradient(135deg, #fa709a, #fee140);
  box-shadow: 0 4px 12px rgba(250,112,154,0.25);
}

.discover-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

/* ---------- 我 页面 ---------- */
.profile-header {
  background: linear-gradient(135deg, var(--primary), #2ecc71);
  margin: 16px;
  border-radius: var(--radius);
  padding: 24px 20px;
  color: white;
  display: flex;
  align-items: center;
  gap: 18px;
  box-shadow: 0 8px 30px rgba(7,193,96,0.3);
}

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
  border: 2px solid rgba(255,255,255,0.4);
}

.profile-info h2 {
  font-size: 20px;
  font-weight: 700;
}

.profile-info p {
  font-size: 14px;
  opacity: 0.85;
  margin-top: 2px;
}

.profile-menu {
  padding: 0 16px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
}

.menu-item:active {
  transform: scale(0.98);
  box-shadow: var(--shadow-lg);
}

.menu-icon {
  font-size: 22px;
  width: 36px;
  text-align: center;
}

.menu-text {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
}

.menu-arrow {
  color: var(--text-muted);
  font-size: 16px;
}

/* ---------- 搜索栏 ---------- */
.search-bar {
  margin: 12px 16px;
  background: var(--bg);
  border-radius: 20px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  transition: border 0.2s;
}

.search-bar:focus-within {
  border-color: var(--primary);
  background: var(--bg-card);
}

.search-bar .search-icon {
  color: var(--text-muted);
  font-size: 18px;
}

.search-bar input {
  flex: 1;
  background: none;
  font-size: 15px;
  color: var(--text-primary);
}

.search-bar input::placeholder {
  color: var(--text-muted);
}

/* ---------- 聊天消息气泡 ---------- */
.chat-messages {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 85%;
}

.message.self {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message .msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.message .bubble {
  background: var(--bg-card);
  padding: 12px 16px;
  border-radius: 18px;
  border-top-left-radius: 4px;
  font-size: 15px;
  box-shadow: var(--shadow);
  line-height: 1.6;
  word-break: break-word;
}

.message.self .bubble {
  background: var(--primary);
  color: white;
  border-radius: 18px;
  border-top-right-radius: 4px;
}

.message .time-label {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin: 8px 0;
  align-self: center;
  width: 100%;
}

/* ---------- 输入区 ---------- */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

.chat-input-area input {
  flex: 1;
  background: var(--bg);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 15px;
  border: 1px solid transparent;
  transition: border 0.2s;
}

.chat-input-area input:focus {
  border-color: var(--primary);
}

.chat-input-area .send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(7,193,96,0.3);
  flex-shrink: 0;
}

.chat-input-area .send-btn:active {
  transform: scale(0.9);
}

/* ---------- 聊天头部 ---------- */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.chat-header .back-btn {
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  transition: transform 0.2s;
}

.chat-header .back-btn:active {
  transform: scale(0.85);
}

.chat-header .chat-title {
  font-size: 17px;
  font-weight: 600;
  flex: 1;
}

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

.empty-state .empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 16px;
}

/* ---------- 响应式微调 ---------- */
@media (min-width: 480px) {
  .app-container {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

@media (max-width: 380px) {
  .discover-grid {
    gap: 8px;
    padding: 12px 8px;
  }
  .discover-item {
    padding: 12px 4px;
  }
  .discover-icon {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
  .chat-avatar {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }
}

/* ---------- 后台管理页面 ---------- */
.admin-body {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 40px 28px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-card .logo {
  font-size: 48px;
  margin-bottom: 8px;
}

.login-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}

.login-card .sub {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 28px;
}

.login-card .input-group {
  margin-bottom: 16px;
  text-align: left;
}

.login-card .input-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 6px;
}

.login-card .input-group input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 15px;
  transition: border 0.2s;
}

.login-card .input-group input:focus {
  border-color: var(--primary);
}

.login-card .login-btn {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(7,193,96,0.3);
  margin-top: 8px;
}

.login-card .login-btn:active {
  transform: scale(0.98);
  box-shadow: 0 2px 8px rgba(7,193,96,0.2);
}

.login-error {
  color: var(--danger);
  font-size: 14px;
  margin-top: 12px;
  min-height: 20px;
}

/* 管理后台内部 */
.admin-panel {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
}

.admin-panel h2 {
  font-size: 22px;
  margin-bottom: 20px;
}

.admin-table {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.admin-table th, .admin-table td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.admin-table th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 13px;
}

.admin-table td .action-btn {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  color: white;
}

.action-btn.edit {
  background: var(--primary);
}

.action-btn.delete {
  background: var(--danger);
}

.action-btn:active {
  transform: scale(0.95);
}

.admin-back {
  display: inline-block;
  margin-bottom: 16px;
  color: var(--primary);
  font-weight: 500;
  cursor: pointer;
}

/* ---------- 通知横幅 ---------- */
.notification-banner {
  background: var(--primary);
  color: white;
  padding: 10px 20px;
  font-size: 14px;
  text-align: center;
  animation: slideDown 0.4s ease;
  position: sticky;
  top: 0;
  z-index: 20;
}

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}