/* 聊天应用样式 */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  height: 100vh;
  overflow: hidden;
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* 屏幕切换 */
.screen {
  display: none;
  height: 100%;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* 登录界面 */
#login-screen {
  justify-content: center;
  align-items: center;
}

.login-container {
  background: white;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 400px;
}

.login-container h1 {
  text-align: center;
  margin-bottom: 30px;
  color: #333;
  font-size: 28px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: #555;
  font-weight: 500;
}

.form-group input[type="text"] {
  width: 100%;
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.3s;
}

.form-group input[type="text"]:focus {
  outline: none;
  border-color: #667eea;
}

.form-group .secondary {
  margin-top: 8px;
  width: 100%;
}

.form-group label input[type="checkbox"] {
  margin-right: 8px;
}

#join-btn, .primary {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

#join-btn:hover, .primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.secondary {
  padding: 10px;
  background: #f5f5f5;
  color: #667eea;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.secondary:hover {
  background: #e8e8e8;
}

.danger {
  padding: 8px 16px;
  background: #ff4757;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.danger:hover {
  background: #ff3344;
}

/* 等待界面 */
#waiting-screen {
  justify-content: center;
  align-items: center;
}

.waiting-container {
  text-align: center;
  color: white;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

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

/* 聊天界面 */
#chat-screen {
  background: #f5f5f5;
}

.chat-header {
  background: white;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e0e0e0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.room-info h2 {
  font-size: 18px;
  color: #333;
  margin-bottom: 4px;
}

.room-info #current-room-id {
  color: #667eea;
}

.room-info #user-count {
  font-size: 14px;
  color: #666;
}

.chat-main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* 用户列表 */
.user-list-panel {
  width: 240px;
  background: white;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
}

.user-list-panel h3 {
  padding: 16px;
  border-bottom: 1px solid #e0e0e0;
  color: #333;
  font-size: 16px;
}

.user-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.user-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border-radius: 8px;
  transition: background 0.2s;
}

.user-item:hover {
  background: #f5f5f5;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  margin-right: 12px;
}

.user-name {
  color: #333;
  font-size: 14px;
}

/* 聊天区域 */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f5f5f5;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-message {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 12px;
  background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.chat-message.me {
  align-self: flex-end;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.chat-message.other {
  align-self: flex-start;
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 12px;
}

.message-name {
  font-weight: 600;
  font-size: 14px;
}

.chat-message.me .message-name {
  color: rgba(255,255,255,0.9);
}

.chat-message.other .message-name {
  color: #667eea;
}

.message-time {
  font-size: 12px;
  opacity: 0.6;
}

.message-text {
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.message-file {
  margin-top: 8px;
}

.message-image {
  max-width: 100%;
  max-height: 300px;
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: transform 0.2s;
}

.message-image:hover {
  transform: scale(1.02);
}

.file-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(0,0,0,0.05);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  transition: background 0.2s;
}

.file-link:hover {
  background: rgba(0,0,0,0.1);
}

.chat-message.me .file-link:hover {
  background: rgba(255,255,255,0.1);
}

.file-icon {
  font-size: 20px;
}

.file-name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
}

.file-size {
  font-size: 12px;
  opacity: 0.7;
}

.system-message {
  text-align: center;
  color: #999;
  font-size: 13px;
  padding: 8px;
  font-style: italic;
}

/* 输入区域 */
.chat-input-area {
  background: white;
  border-top: 1px solid #e0e0e0;
  padding: 16px 20px;
  flex-shrink: 0;
}

.input-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #f5f5f5;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 18px;
}

.tool-btn:hover {
  background: #e8e8e8;
}

.file-preview {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #e0e0e0;
}

.file-preview:not(:empty) {
  display: flex;
}

.file-count {
  font-size: 12px;
  color: #999;
  margin-top: 8px;
  display: block;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: #f5f5f5;
  border-radius: 6px;
  font-size: 13px;
}

.file-icon {
  font-size: 16px;
}

.file-name {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  color: #999;
  font-size: 12px;
}

.input-wrapper {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  width: 100%;
}

#chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  min-height: 44px;
  transition: border-color 0.3s;
  width: 100%;
}

#chat-input:focus {
  outline: none;
  border-color: #667eea;
}

#send-btn {
  padding: 12px 24px;
  min-width: 80px;
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .user-list-panel {
    display: none;
  }
  
  .chat-message {
    max-width: 85%;
  }
  
  .login-container {
    margin: 20px;
    padding: 30px 20px;
  }
  
  .chat-input-area {
    padding: 12px;
  }
  
  .input-wrapper {
    gap: 8px;
  }
  
  #chat-input {
    min-height: 40px;
    font-size: 16px; /* 防止 iOS 缩放 */
  }
  
  #send-btn {
    padding: 10px 16px;
    min-width: 60px;
  }
}
