/* ===== 全局变量 ===== */
:root {
  --primary: #6366f1;
  --primary-light: #8183f2;
  --primary-dark: #4f52e0;
  --success: #10b981;
  --bg-light: #ffffff;
  --bg-dark: #1f2937;
  --text-light: #111827;
  --text-dark: #f3f4f6;
  --border-light: #e5e7eb;
  --border-dark: #374151;
  --message-self-light: #dbeafe;
  --message-self-dark: #2563eb;
  --message-other-light: #f3f4f6;
  --message-other-dark: #374151;
  --header-light: #f9fafb;
  --header-dark: #111827;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

[data-theme="light"] {
  --bg: var(--bg-light);
  --text: var(--text-light);
  --border: var(--border-light);
  --message-self: var(--message-self-light);
  --message-other: var(--message-other-light);
  --header-bg: var(--header-light);
  --input-bg: white;
}

[data-theme="dark"] {
  --bg: var(--bg-dark);
  --text: var(--text-dark);
  --border: var(--border-dark);
  --message-self: var(--message-self-dark);
  --message-other: var(--message-other-dark);
  --header-bg: var(--header-dark);
  --input-bg: #374151;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background-color 0.3s, color 0.3s;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== 通用头部 ===== */
.app-header {
  background-color: var(--header-bg);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.header-title {
  font-size: 1.25rem;
  font-weight: 600;
}
.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}
.icon-btn:hover {
  background-color: var(--border);
}

/* ===== 登录/注册卡片 ===== */
.auth-container {
  max-width: 400px;
  margin: 2rem auto;
  padding: 2rem;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  box-shadow: var(--shadow);
}
.auth-container h2 {
  margin-bottom: 1.5rem;
  text-align: center;
}
.auth-form .form-group {
  margin-bottom: 1rem;
}
.auth-form label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 500;
}
.auth-form input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background-color: var(--input-bg);
  color: var(--text);
}
.auth-form button {
  width: 100%;
  padding: 0.75rem;
  background-color: var(--primary);
  color: white;
  border: none;
  border-radius: 0.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s;
}
.auth-form button:hover {
  background-color: var(--primary-dark);
}
.auth-link {
  text-align: center;
  margin-top: 1rem;
}
.auth-link a {
  color: var(--primary);
  text-decoration: none;
}

/* ===== 主聊天布局 ===== */
.chat-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}
.sidebar {
  width: 280px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  transition: transform 0.3s ease;
}
.sidebar.collapsed {
  transform: translateX(-100%);
}
.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}
.friend-search {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.friend-search input {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background-color: var(--input-bg);
  color: var(--text);
}
.friend-search button {
  padding: 0.5rem 0.75rem;
  background-color: var(--primary);
  color: white;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
}
.friend-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
}
.friend-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 0.2s;
}
.friend-item:hover, .friend-item.active {
  background-color: var(--border);
}
.friend-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  flex-shrink: 0;
}
.friend-info {
  flex: 1;
  min-width: 0;
}
.friend-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.friend-preview {
  font-size: 0.875rem;
  color: var(--text);
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.main-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.message {
  display: flex;
  gap: 0.75rem;
  max-width: 80%;
}
.message.self {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  flex-shrink: 0;
}
.message-content {
  display: flex;
  flex-direction: column;
}
.message-bubble {
  padding: 0.5rem 0.75rem;
  border-radius: 1rem;
  background-color: var(--message-other);
  color: var(--text);
  word-wrap: break-word;
}
.message.self .message-bubble {
  background-color: var(--primary);
  color: white;
}
.message-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  margin-top: 0.125rem;
  opacity: 0.7;
}
.chat-input-area {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
}
.chat-input-area input {
  flex: 1;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 2rem;
  background-color: var(--input-bg);
  color: var(--text);
}
.chat-input-area button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.menu-toggle {
  display: none;
}
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 10;
    box-shadow: var(--shadow);
  }
  .menu-toggle {
    display: block;
  }
  .main-chat {
    width: 100%;
  }
}

/* ===== 设置页面 ===== */
.settings-container {
  max-width: 600px;
  margin: 2rem auto;
  padding: 2rem;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
}
.settings-section {
  margin-bottom: 2rem;
}
.settings-section h3 {
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.profile-info {
  display: flex;
  gap: 1.5rem;
  align-items: center;
}
.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 2rem;
  font-weight: bold;
}
.profile-details p {
  margin: 0.25rem 0;
}
.theme-selector {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.theme-btn {
  padding: 0.5rem 1rem;
  background-color: var(--border);
  border: none;
  border-radius: 2rem;
  color: var(--text);
  cursor: pointer;
}
.theme-btn.active {
  background-color: var(--primary);
  color: white;
}
.danger-btn {
  background-color: #ef4444;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  cursor: pointer;
}