:root {
  --app-sidebar-bg: #0099ff;
  --app-sidebar-width: 60px;
  --list-panel-width: 280px;
  --list-bg: #fdfdfd;
  --list-active: #f2f2f2;
  --main-bg: #f5f6f7;
  --info-sidebar-width: 240px;
  --info-bg: #fff;
  --border-color: #e7e7e7;
  --primary-blue: #0099ff;
  --text-primary: #333;
  --text-secondary: #666;
  --text-tertiary: #999;
  --bg-bubble: #fff;
  --bg-bubble-me: #0099ff;
  --text-bubble-me: #fff;
  --shadow-color: rgba(0, 0, 0, 0.05);
}

/* 黑夜模式变量 */
[data-theme="dark"] {
  --app-sidebar-bg: #1a1a2e;
  --list-bg: #16213e;
  --list-active: #1a1a2e;
  --main-bg: #0f0f23;
  --info-bg: #16213e;
  --border-color: #2a2a4a;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0a0;
  --text-tertiary: #707070;
  --bg-bubble: #1e1e3f;
  --bg-bubble-me: #4a4aff;
  --text-bubble-me: #fff;
  --shadow-color: rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
  height: 100vh;
  overflow: hidden;
  background-color: var(--main-bg);
  color: var(--text-primary);
  /* 移动端安全区域支持 */
  padding-bottom: env(safe-area-inset-bottom);
  /* 主题切换动画 */
  transition: background-color 0.3s ease, color 0.3s ease;
}

.app-container {
  display: flex;
  height: 100%;
  width: 100%;
  /* 移动端底部安全区域 */
  padding-bottom: env(safe-area-inset-bottom);
  box-sizing: border-box;
}

/* 1. App Sidebar (Leftmost) */
.app-sidebar {
  width: var(--app-sidebar-width);
  background-color: var(--app-sidebar-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  color: #aaddff;
}

.user-avatar-small {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding: 8px 0 16px 0;
}

.user-avatar-small img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8);
  transition: transform 0.2s, border-color 0.2s;
}

.user-avatar-small img:hover {
  transform: scale(1.05);
  border-color: #fff;
}

.nav-icons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  width: 100%;
  padding: 0 8px;
}

.nav-item {
  width: 44px;
  height: 44px;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 12px;
}

.nav-item:hover {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.15);
}

.nav-item.active {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.2);
}

.nav-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 0 8px;
}

/* 2. Chat List Panel */
.chat-list-panel {
  width: var(--list-panel-width);
  background-color: var(--list-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

.search-bar-container {
  padding: 16px;
  -webkit-app-region: drag;
}

.search-input-wrapper {
  background-color: var(--list-active);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-tertiary);
  font-size: 14px;
  transition: box-shadow 0.2s;
}

.search-input-wrapper:focus-within {
  box-shadow: 0 0 0 2px rgba(0, 153, 255, 0.2);
}

.search-input-wrapper input {
  border: none;
  background: transparent;
  width: 100%;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
}

.search-input-wrapper input::placeholder {
  color: var(--text-tertiary);
}

.action-icon {
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.2s, color 0.2s;
  flex-shrink: 0;
}

.action-icon:hover {
  background-color: rgba(0, 153, 255, 0.1);
  color: var(--primary-blue);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-list::-webkit-scrollbar {
  width: 6px;
}

.chat-list::-webkit-scrollbar-thumb {
  background: #e0e0e0;
  border-radius: 3px;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  position: relative;
  transition: background-color 0.15s;
}

.chat-item:hover {
  background-color: var(--list-active);
}

.chat-item.active {
  background-color: var(--list-active);
}

.chat-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 32px;
  background-color: var(--primary-blue);
  border-radius: 0 2px 2px 0;
}

.item-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  margin-right: 12px;
  background-color: #ddd;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: #fff;
  flex-shrink: 0;
}

.item-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.item-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  gap: 4px;
}

.item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.item-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.item-time {
  font-size: 12px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.item-msg {
  font-size: 13px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  background-color: #ff4d4f;
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
  font-weight: 500;
}

.chat-item.active .badge {
  background-color: #ff7875;
}


/* 3. Main Chat Area */
.main-chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--main-bg);
  min-width: 400px;
  transition: background-color 0.3s ease;
}

.chat-header {
  height: 64px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background-color: var(--main-bg);
}

.chat-title h2 {
  font-size: 16px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  margin: 0;
}

.member-count {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
}

.header-actions {
  color: var(--text-secondary);
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-actions i {
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background-color 0.2s, color 0.2s;
}

.header-actions i:hover {
  background-color: rgba(0, 153, 255, 0.1);
  color: var(--primary-blue);
}

.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.message-time-divider {
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
  margin: 8px 0;
  padding: 4px 12px;
  background-color: rgba(0, 0, 0, 0.03);
  border-radius: 12px;
  display: inline-block;
  align-self: center;
}

.message-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 4px 0;
}

.message-row.me {
  flex-direction: row-reverse;
}

.message-avatar {
  flex-shrink: 0;
}

.message-avatar img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.message-body {
  display: flex;
  flex-direction: column;
  max-width: 65%;
  gap: 4px;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-tertiary);
}

.message-row.me .message-meta {
  flex-direction: row-reverse;
}

.user-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
  font-weight: 500;
}

.user-badge.admin {
  color: #0099ff;
  border-color: #0099ff;
  background-color: rgba(0, 153, 255, 0.08);
}

.user-badge.owner {
  color: #ffaa00;
  border-color: #ffaa00;
  background-color: rgba(255, 170, 0, 0.08);
}

.user-badge.normal {
  color: #999;
  border-color: #ddd;
  background-color: rgba(0, 0, 0, 0.02);
}

.user-name {
  font-weight: 500;
}

.message-bubble {
  background-color: var(--bg-bubble);
  padding: 12px 16px;
  border-radius: 4px 16px 16px 16px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  position: relative;
  box-shadow: 0 1px 2px var(--shadow-color);
  word-wrap: break-word;
  transition: background-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

.message-row.me .message-bubble {
  background-color: var(--bg-bubble-me);
  color: var(--text-bubble-me);
  border-radius: 16px 4px 16px 16px;
}

.image-bubble {
  padding: 8px;
  border-radius: 12px;
}

.image-bubble img {
  max-width: 200px;
  border-radius: 8px;
  display: block;
}


/* Input Area */
.chat-input-area {
  height: auto;
  min-height: 140px;
  max-height: 300px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  background-color: var(--main-bg);
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.tool-left,
.tool-right {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
}

.tool-left i,
.tool-right i {
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}

.tool-left i:hover,
.tool-right i:hover {
  color: var(--primary-blue);
  background-color: rgba(0, 153, 255, 0.1);
}

textarea {
  flex: 1;
  background: transparent;
  border: none;
  resize: none;
  padding: 8px 20px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  outline: none;
  min-height: 60px;
  max-height: 200px;
  overflow-y: auto;
  color: var(--text-primary);
}

textarea::placeholder {
  color: var(--text-tertiary);
}

.input-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 12px 20px;
  gap: 0;
  flex-shrink: 0;
}

#send {
  background-color: var(--primary-blue);
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: 6px 0 0 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background-color 0.2s;
}

#send:hover {
  background-color: #0088ee;
}

.arrow-btn {
  background-color: var(--primary-blue);
  color: white;
  border: none;
  padding: 8px 10px;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  border-left: 1px solid rgba(255, 255, 255, 0.2);
  transition: background-color 0.2s;
}

.arrow-btn:hover {
  background-color: #0088ee;
}


/* 4. Info Sidebar (Rightmost) */
.info-sidebar {
  width: var(--info-sidebar-width);
  background: var(--info-bg);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  font-size: 13px;
}

.notice-section {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.notice-section h3 {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.notice-content {
  color: var(--text-primary);
  line-height: 1.5;
  font-size: 13px;
}

.search-member {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-secondary);
}

.header-row h3 {
  font-size: 13px;
  font-weight: 500;
  margin: 0;
}

.header-row i {
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}

.header-row i:hover {
  background-color: rgba(0, 153, 255, 0.1);
  color: var(--primary-blue);
}

.member-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
}

.member-list::-webkit-scrollbar {
  width: 4px;
}

.member-list::-webkit-scrollbar-thumb {
  background: #eee;
  border-radius: 2px;
}

.member-item {
  display: flex;
  align-items: center;
  padding: 10px 0;
  gap: 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}

.member-item:last-child {
  border-bottom: none;
}

.member-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
}

.member-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
  font-size: 13px;
}

.role-tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
  flex-shrink: 0;
}

.role-tag.owner {
  background: linear-gradient(135deg, #ffaa00, #ff8800);
  color: white;
}

.role-tag.admin {
  background: linear-gradient(135deg, #23d18b, #1db870);
  color: white;
}

/* ============================================
   响应式设计 - Responsive Design
   ============================================ */

/* 平板适配 (768px - 1024px) */
@media (max-width: 1024px) {
  /* 隐藏右侧信息栏 */
  .info-sidebar {
    display: none;
  }

  /* 减小聊天列表面板宽度 */
  .chat-list-panel {
    width: 240px;
  }

  .main-chat-area {
    min-width: 320px;
  }
}

/* 手机适配 (<768px) */
@media (max-width: 767px) {
  :root {
    --app-sidebar-width: 0;
  }

  /* 隐藏左侧应用导航栏 */
  .app-sidebar {
    display: none;
  }

  /* 移动端黑夜模式按钮样式优化 */
  .theme-toggle-btn {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  /* 隐藏右侧信息栏 */
  .info-sidebar {
    display: none;
  }

  /* 聊天列表面板变为可滑动的抽屉 */
  .chat-list-panel {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    width: 280px;
    z-index: 1000;
    transition: left 0.3s ease, transform 0.3s ease;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
  }

  .chat-list-panel.open {
    left: 0;
  }

  /* 主聊天区域占据全屏 */
  .main-chat-area {
    width: 100%;
    min-width: 100%;
    /* 移动端底部安全区域 */
    padding-bottom: env(safe-area-inset-bottom);
    box-sizing: border-box;
  }

  /* 添加移动端顶部导航栏 */
  .chat-header {
    padding: 0 8px;
    height: 56px;
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    gap: 8px;
  }

  .chat-title {
    text-align: center;
  }

  .chat-title h2 {
    font-size: 16px;
    margin: 0;
    justify-content: center;
  }

  .header-actions {
    gap: 15px;
  }

  /* 调整消息区域 */
  .chat-messages {
    padding: 12px;
    gap: 15px;
  }

  .message-avatar img {
    width: 28px;
    height: 28px;
  }

  .message-body {
    max-width: 80%;
  }

  .message-bubble {
    font-size: 13px;
    padding: 8px 12px;
  }

  /* 调整输入区域高度 - 使用 flex 布局确保所有元素可见 */
  .chat-input-area {
    height: auto;
    min-height: 120px;
    max-height: 40vh;
    /* 移动端底部安全区域 */
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .toolbar {
    padding: 8px 12px;
    flex-shrink: 0;
  }

  .tool-left,
  .tool-right {
    gap: 12px;
    font-size: 16px;
  }

  textarea {
    padding: 8px 12px;
    font-size: 16px;
    flex: 1;
    min-height: 40px;
    max-height: 150px;
    resize: none;
    overflow-y: auto;
  }

  .input-actions {
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    flex-shrink: 0;
    display: flex;
    gap: 0;
  }

  /* 添加遮罩层 */
  .overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .overlay.active {
    display: block;
    opacity: 1;
  }

  /* 防止移动端滚动穿透 */
  .chat-list-panel.open ~ .main-chat-area {
    pointer-events: none;
  }

  .overlay.active ~ .main-chat-area {
    pointer-events: none;
  }
}

/* 小屏手机适配 (<480px) */
@media (max-width: 479px) {
  .chat-header {
    height: 50px;
  }

  .chat-title h2 {
    font-size: 14px;
  }

  .member-count {
    display: none;
  }

  .header-actions {
    gap: 12px;
    font-size: 16px;
  }

  .chat-messages {
    padding: 10px;
    gap: 12px;
  }

  .message-avatar img {
    width: 24px;
    height: 24px;
  }

  .message-body {
    max-width: 85%;
  }

  .message-bubble {
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 6px;
  }

  .message-meta {
    font-size: 11px;
    gap: 4px;
    margin-bottom: 3px;
  }

  .user-badge {
    font-size: 9px;
    padding: 0 3px;
  }

  /* 输入区域进一步优化 - 小屏手机 */
  .chat-input-area {
    min-height: 100px;
    max-height: 35vh;
    /* 移动端底部安全区域 */
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
  }

  .toolbar {
    padding: 6px 10px;
  }

  .tool-left,
  .tool-right {
    gap: 10px;
    font-size: 15px;
  }

  textarea {
    padding: 6px 10px;
    font-size: 16px;
    min-height: 36px;
    max-height: 120px;
  }

  .input-actions {
    padding: 6px 10px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
  }

  #send {
    padding: 8px 14px;
    font-size: 14px;
    min-height: 36px;
  }

  .arrow-btn {
    padding: 8px 10px;
    min-height: 36px;
  }
}

/* 横屏模式优化 */
@media (max-width: 767px) and (orientation: landscape) {
  .chat-input-area {
    min-height: 80px;
    max-height: 25vh;
    /* 移动端底部安全区域 */
    padding-bottom: calc(4px + env(safe-area-inset-bottom));
  }

  .chat-messages {
    padding: 8px;
    gap: 10px;
  }

  .toolbar {
    padding: 5px 10px;
  }

  textarea {
    min-height: 32px;
    max-height: 80px;
    padding: 4px 10px;
  }

  .input-actions {
    padding: 4px 10px;
    padding-bottom: calc(4px + env(safe-area-inset-bottom));
  }

  #send,
  .arrow-btn {
    min-height: 32px;
    padding: 6px 12px;
  }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
  /* 增大触摸目标 */
  .chat-item {
    padding: 15px;
    -webkit-tap-highlight-color: transparent;
  }

  .chat-item:active {
    background-color: #e8e8e8;
    transition: background-color 0.1s;
  }

  .nav-item {
    padding: 8px;
    -webkit-tap-highlight-color: transparent;
  }

  .nav-item:active {
    transform: scale(0.95);
  }

  .tool-left i,
  .tool-right i {
    padding: 10px;
    -webkit-tap-highlight-color: transparent;
    display: inline-block;
  }

  .tool-left i:active,
  .tool-right i:active {
    transform: scale(0.9);
  }

  #send,
  .arrow-btn {
    min-height: 44px;
    min-width: 44px;
    -webkit-tap-highlight-color: transparent;
  }

  #send:active,
  .arrow-btn:active {
    transform: scale(0.98);
  }

  /* 移动端按钮触摸优化 */
  .mobile-menu-btn,
  .mobile-back-btn {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-menu-btn:active,
  .mobile-back-btn:active {
    transform: scale(0.95);
    background-color: rgba(0, 153, 255, 0.1);
    border-radius: 50%;
  }

  /* 滚动条样式优化 */
  .chat-list::-webkit-scrollbar,
  .chat-messages::-webkit-scrollbar,
  .member-list::-webkit-scrollbar {
    width: 4px;
  }

  /* 输入框触摸优化 */
  textarea {
    font-size: 16px; /* 防止 iOS 自动缩放 */
  }

  /* 聊天头像点击反馈 */
  .user-avatar-small {
    transition: transform 0.2s;
  }

  .user-avatar-small:active {
    transform: scale(0.95);
  }
}

/* 高对比度/深色模式支持 */
@media (prefers-color-scheme: dark) {
  :root {
    --list-bg: #1a1a1a;
    --list-active: #2a2a2a;
    --main-bg: #0f0f0f;
    --info-bg: #1a1a1a;
    --border-color: #333;
  }

  body {
    background-color: #000;
  }

  .search-input-wrapper {
    background-color: #2a2a2a;
  }

  .search-input-wrapper input {
    color: #fff;
  }

  .item-name {
    color: #fff;
  }

  .message-bubble {
    background-color: #2a2a2a;
    color: #fff;
  }

  textarea {
    color: #fff;
  }

  .notice-content {
    color: #ccc;
  }

  .member-name {
    color: #fff;
  }

  .overlay {
    background-color: rgba(255, 255, 255, 0.5);
  }

  .user-modal-content {
    background-color: #2a2a2a;
  }

  .user-modal-content h3 {
    color: #fff;
  }

  #usernameInput {
    background-color: #1a1a1a;
    color: #fff;
    border-color: #444;
  }
}

/* ============================================
   黑夜模式切换按钮样式
   ============================================ */

.theme-toggle-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  color: #fff;
  font-size: 18px;
  margin-bottom: 8px;
}

.theme-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.5);
  transform: scale(1.05);
}

.theme-toggle-btn:active {
  transform: scale(0.95);
}

.theme-toggle-btn i {
  transition: transform 0.5s ease;
}

/* 太阳/月亮旋转动画 */
[data-theme="dark"] .theme-toggle-btn i.fa-moon,
.theme-toggle-btn i.fa-sun {
  transform: rotate(360deg);
}

.theme-toggle-btn i.fa-sun {
  animation: sun-glow 2s ease-in-out infinite;
}

@keyframes sun-glow {
  0%, 100% {
    filter: drop-shadow(0 0 3px rgba(255, 200, 0, 0.5));
  }
  50% {
    filter: drop-shadow(0 0 8px rgba(255, 200, 0, 0.8));
  }
}

/* 头部黑夜模式按钮样式 */
.header-theme-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(0, 153, 255, 0.1);
  border-color: rgba(0, 153, 255, 0.3);
  color: var(--primary-blue);
  font-size: 16px;
  margin: 0;
  margin-right: 8px;
}

.header-theme-btn:hover {
  background: rgba(0, 153, 255, 0.2);
  border-color: rgba(0, 153, 255, 0.5);
}

/* ============================================
   移动端导航按钮样式
   ============================================ */

.mobile-menu-btn,
.mobile-back-btn {
  display: none;
  background: none;
  border: none;
  font-size: 18px;
  color: #666;
  padding: 8px;
  cursor: pointer;
  transition: color 0.2s;
}

.mobile-menu-btn:hover,
.mobile-back-btn:hover {
  color: #0099ff;
}

.desktop-only {
  display: flex;
}

/* ============================================
   用户设置模态框样式
   ============================================ */

.user-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.user-modal.active {
  display: flex;
}

.user-modal-content {
  background-color: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 320px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.user-modal-content h3 {
  font-size: 18px;
  font-weight: 500;
  color: #333;
  margin-bottom: 16px;
  text-align: center;
}

#usernameInput {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
  margin-bottom: 16px;
}

#usernameInput:focus {
  border-color: #0099ff;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.2s;
  font-family: inherit;
}

#cancelUsername {
  background-color: #f5f5f5;
  color: #666;
}

#cancelUsername:hover {
  background-color: #e8e8e8;
}

#saveUsername {
  background-color: #0099ff;
  color: #fff;
}

#saveUsername:hover {
  background-color: #0088ee;
}

/* ============================================
   移动端特定样式
   ============================================ */

@media (max-width: 767px) {
  .mobile-menu-btn,
  .mobile-back-btn {
    display: block;
  }

  .desktop-only {
    display: none;
  }

  .chat-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 8px;
  }

  /* 返回按钮在聊天列表页隐藏 */
  .chat-list-panel ~ .main-chat-area .mobile-back-btn {
    display: block;
  }

  /* 聊天列表页显示菜单按钮 */
  .chat-list-panel.open ~ .main-chat-area .mobile-menu-btn {
    display: none;
  }

  /* 聊天详情页显示返回按钮 */
  .chat-list-panel:not(.open) ~ .main-chat-area .mobile-back-btn {
    display: block;
  }

  .chat-list-panel:not(.open) ~ .main-chat-area .mobile-menu-btn {
    display: block;
  }
}

/* ============================================
   动画效果
   ============================================ */

@keyframes slideIn {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.chat-list-panel.open {
  animation: slideIn 0.3s ease;
}

.overlay.active {
  animation: fadeIn 0.3s ease;
}

.user-modal.active {
  animation: fadeIn 0.2s ease;
}

/* ============================================
   焦点可见性（无障碍）
   ============================================ */

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid #0099ff;
  outline-offset: 2px;
}

/* ============================================
   打印样式
   ============================================ */

@media print {
  .app-sidebar,
  .chat-list-panel,
  .info-sidebar,
  .chat-input-area,
  .toolbar,
  .header-actions,
  .mobile-menu-btn,
  .mobile-back-btn {
    display: none !important;
  }

  .main-chat-area {
    width: 100%;
  }

  .chat-messages {
    overflow: visible;
  }
}

/* ============================================
   引用回复样式
   ============================================ */

/* 输入框上方的引用预览 */
.reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background-color: rgba(0, 153, 255, 0.08);
  border-left: 3px solid var(--primary-blue);
  margin: 0 12px;
  border-radius: 0 8px 8px 0;
}

.reply-preview-content {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.reply-preview-content i {
  color: var(--primary-blue);
  font-size: 14px;
}

.reply-preview-user {
  font-weight: 500;
  color: var(--primary-blue);
  flex-shrink: 0;
}

.reply-preview-text {
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-cancel-btn {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.reply-cancel-btn:hover {
  background-color: rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
}

/* 消息气泡内的引用块 */
.reply-quote {
  background-color: rgba(0, 0, 0, 0.05);
  border-left: 2px solid var(--primary-blue);
  padding: 6px 10px;
  margin-bottom: 8px;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  transition: background-color 0.2s;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reply-quote:hover {
  background-color: rgba(0, 0, 0, 0.08);
}

.reply-quote-user {
  font-weight: 500;
  color: var(--primary-blue);
}

.reply-quote-text {
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* 自己消息的引用块样式 */
.message-row.me .reply-quote {
  background-color: rgba(255, 255, 255, 0.15);
  border-left-color: rgba(255, 255, 255, 0.5);
}

.message-row.me .reply-quote:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.message-row.me .reply-quote-user {
  color: rgba(255, 255, 255, 0.9);
}

.message-row.me .reply-quote-text {
  color: rgba(255, 255, 255, 0.7);
}

/* 消息高亮动画（点击引用跳转时） */
.message-row.highlight .message-bubble {
  animation: highlight-pulse 2s ease-out;
}

@keyframes highlight-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(0, 153, 255, 0.5);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(0, 153, 255, 0.2);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(0, 153, 255, 0);
  }
}

/* 消息气泡点击提示 */
.message-bubble {
  cursor: pointer;
}

.message-bubble:hover {
  filter: brightness(0.98);
}

/* 黑夜模式下的引用样式 */
[data-theme="dark"] .reply-preview {
  background-color: rgba(74, 74, 255, 0.15);
}

[data-theme="dark"] .reply-quote {
  background-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .reply-quote:hover {
  background-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .reply-cancel-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
}