* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; background: #f0f2f5; color: #333; height: 100vh; overflow: hidden; }
input, textarea, button { font-family: inherit; font-size: 14px; }
a { color: #07c; text-decoration: none; }
.hidden { display: none !important; }

/* ========== Auth Pages ========== */
.auth-container { display: flex; align-items: center; justify-content: center; height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.auth-box { background: #fff; border-radius: 12px; padding: 40px; width: 400px; max-width: 90vw; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.auth-tabs { display: flex; gap: 0; margin-bottom: 24px; border-bottom: 2px solid #eee; }
.tab-btn { flex: 1; padding: 12px; border: none; background: none; font-size: 16px; cursor: pointer; color: #999; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .2s; }
.tab-btn.active { color: #667eea; border-bottom-color: #667eea; font-weight: 600; }
.auth-form h2 { margin-bottom: 20px; font-size: 22px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 14px; color: #666; }
.form-group input { width: 100%; padding: 10px 14px; border: 1px solid #ddd; border-radius: 8px; font-size: 15px; transition: border .2s; }
.form-group input:focus { outline: none; border-color: #667eea; box-shadow: 0 0 0 3px rgba(102,126,234,.15); }
.btn-primary { width: 100%; padding: 12px; background: #667eea; color: #fff; border: none; border-radius: 8px; font-size: 16px; cursor: pointer; transition: background .2s; }
.btn-primary:hover { background: #5a6fd6; }
.error { color: #e74c3c; font-size: 13px; margin-top: 8px; min-height: 20px; }

/* ========== Main Layout ========== */
#app { display: flex; height: 100vh; }

/* ========== Sidebar ========== */
#sidebar { width: 300px; min-width: 300px; background: #fff; border-right: 1px solid #e8e8e8; display: flex; flex-direction: column; }
.sidebar-header { padding: 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #f0f0f0; }
.user-info { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #667eea; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 600; }
.nickname { font-weight: 600; font-size: 15px; }
.status { font-size: 12px; }
.status.online { color: #2ecc71; }
.status.offline { color: #bbb; }
.status.busy { color: #e67e22; }
.sidebar-actions { display: flex; gap: 4px; }
.sidebar-actions button { width: 32px; height: 32px; border: 1px solid #e0e0e0; border-radius: 8px; background: #f8f8f8; cursor: pointer; font-size: 16px; display: flex; align-items: center; justify-content: center; transition: all .2s; }
.sidebar-actions button:hover { background: #667eea; color: #fff; border-color: #667eea; }

.search-box { padding: 10px 16px; }
.search-box input { width: 100%; padding: 8px 12px; border: 1px solid #e8e8e8; border-radius: 8px; background: #f5f5f5; }
.search-box input:focus { outline: none; border-color: #667eea; }

.contact-tabs { display: flex; border-bottom: 1px solid #f0f0f0; }
.contact-tab { flex: 1; padding: 10px; border: none; background: none; cursor: pointer; font-size: 14px; color: #999; transition: all .2s; position: relative; }
.contact-tab.active { color: #667eea; font-weight: 600; }
.contact-tab:hover { color: #667eea; }
.badge { position: absolute; top: 4px; right: 10px; background: #e74c3c; color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 10px; }

.contact-list { flex: 1; overflow-y: auto; }
.contact-item { display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; transition: background .15s; border-bottom: 1px solid #f8f8f8; }
.contact-item:hover { background: #f5f7ff; }
.contact-item.active { background: #eef0ff; }
.contact-avatar { width: 40px; height: 40px; border-radius: 50%; background: #667eea; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.group-avatar { background: #e67e22; }
.contact-info { flex: 1; min-width: 0; }
.contact-name { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-preview { font-size: 12px; color: #999; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-status { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.contact-status.online { background: #2ecc71; }
.contact-status.offline { background: #ddd; }
.empty-tip { text-align: center; padding: 40px 20px; color: #999; }

/* ========== Main Area ========== */
#mainArea { flex: 1; display: flex; flex-direction: column; }
.chat-header { padding: 14px 20px; border-bottom: 1px solid #f0f0f0; display: flex; align-items: center; justify-content: space-between; background: #fff; }
.chat-title { font-size: 16px; font-weight: 600; }
.chat-actions button { width: 32px; height: 32px; border: 1px solid #e0e0e0; border-radius: 8px; background: #f8f8f8; cursor: pointer; font-size: 16px; }

.message-area { flex: 1; overflow-y: auto; background: #f8f9fc; }
.no-chat-selected { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: #bbb; }
.no-chat-icon { font-size: 64px; margin-bottom: 16px; }

.messages-container { padding: 16px 20px; display: flex; flex-direction: column; gap: 8px; }
.message { max-width: 70%; padding: 0; }
.message-mine { align-self: flex-end; }
.message-other { align-self: flex-start; }
.msg-sender { font-size: 12px; color: #999; margin-bottom: 4px; }
.msg-content { padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.5; word-break: break-word; }
.message-mine .msg-content { background: #667eea; color: #fff; border-bottom-right-radius: 4px; }
.message-other .msg-content { background: #fff; border-bottom-left-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.msg-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; padding: 0 4px; }
.msg-time { font-size: 11px; color: #bbb; }
.recall-btn { font-size: 11px; color: #667eea; cursor: pointer; display: none; }
.message:hover .recall-btn { display: inline; }
.recalled-msg { color: #bbb; font-style: italic; font-size: 13px; }
.voice-msg { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 0; }
.voice-msg.playing .voice-icon { animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.2); } }
.voice-duration { font-size: 12px; }

.msg-image { max-width: 240px; max-height: 240px; border-radius: 8px; cursor: pointer; }

/* ========== Input Area ========== */
.input-area { background: #fff; border-top: 1px solid #f0f0f0; padding: 10px 16px 16px; }
.input-toolbar { display: flex; gap: 8px; margin-bottom: 8px; }
.input-toolbar button { width: 36px; height: 36px; border: 1px solid #e0e0e0; border-radius: 8px; background: #f8f8f8; cursor: pointer; font-size: 16px; display: flex; align-items: center; justify-content: center; transition: all .2s; }
.input-toolbar button:hover { background: #eef0ff; border-color: #667eea; }
.input-wrapper { display: flex; gap: 10px; }
.input-wrapper textarea { flex: 1; padding: 10px 14px; border: 1px solid #e0e0e0; border-radius: 10px; resize: none; font-size: 14px; line-height: 1.5; }
.input-wrapper textarea:focus { outline: none; border-color: #667eea; }
.btn-send { padding: 10px 24px; background: #667eea; color: #fff; border: none; border-radius: 10px; cursor: pointer; font-size: 15px; font-weight: 500; transition: background .2s; align-self: flex-end; }
.btn-send:hover { background: #5a6fd6; }

/* ========== Modals ========== */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-content { background: #fff; border-radius: 12px; padding: 28px; width: 420px; max-width: 90vw; max-height: 80vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-content h3 { margin-bottom: 16px; font-size: 18px; }
.modal-content input[type="text"] { width: 100%; padding: 10px 14px; border: 1px solid #ddd; border-radius: 8px; margin-bottom: 12px; font-size: 14px; }
.modal-content input:focus { outline: none; border-color: #667eea; }
.modal-content button { padding: 8px 16px; border-radius: 8px; border: 1px solid #ddd; background: #fff; cursor: pointer; font-size: 13px; }
.modal-content button:hover { background: #f0f0f0; }
.modal-content .btn-primary { width: auto; margin-top: 12px; }

.search-results { max-height: 300px; overflow-y: auto; }
.search-user-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid #f0f0f0; }
.search-user-item button { background: #667eea; color: #fff; border: none; }

.member-select { max-height: 240px; overflow-y: auto; margin-bottom: 12px; }
.member-checkbox { display: flex; align-items: center; gap: 8px; padding: 6px 0; cursor: pointer; }
.member-checkbox input { width: auto; margin: 0; }

.request-section { background: #fff8e8; border-radius: 8px; margin: 8px 12px; padding: 8px 12px; border: 1px solid #f0dca0; }
.request-section-title { font-size: 12px; color: #b8860b; font-weight: 600; margin-bottom: 6px; }
.request-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid #f0f0f0; }
.request-item span { flex: 1; }
.request-item button:first-of-type { background: #2ecc71; color: #fff; border: none; }
.request-item button:last-of-type { color: #e74c3c; }

.member-list { max-height: 300px; overflow-y: auto; }
.member-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #f0f0f0; font-size: 14px; }
.member-item button { font-size: 12px; }

/* ========== Voice Recorder ========== */
.recorder-ui { text-align: center; }
.recording-timer { font-size: 36px; font-weight: 700; color: #667eea; margin: 20px 0; }
.recording-wave { height: 60px; margin: 10px 0; }
.recorder-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }
.recorder-buttons button { padding: 10px 24px; border-radius: 20px; }
#recordBtn { background: #e74c3c; color: #fff; border: none; }
#sendVoiceBtn { background: #2ecc71; color: #fff; border: none; }
#sendVoiceBtn:disabled { background: #ddd; }

/* ========== Call UI ========== */
.call-ui { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,.85); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 2000; color: #fff; }
.call-ui.calling { background: rgba(0,0,0,.8); }
.call-ui.connected { background: rgba(0,0,0,.7); }
.call-ui.ended { background: rgba(0,0,0,.6); animation: fadeOut 1s forwards; }
@keyframes fadeOut { to { opacity: 0; visibility: hidden; } }
.call-ui span { font-size: 20px; margin-bottom: 30px; }
.call-ui button { padding: 14px 40px; border-radius: 30px; border: none; font-size: 16px; cursor: pointer; background: #e74c3c; color: #fff; }

/* ========== Context Menu ========== */
.context-menu { position: fixed; background: #fff; border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,.15); z-index: 3000; min-width: 140px; padding: 6px 0; overflow: hidden; }
.context-menu-item { padding: 10px 18px; font-size: 14px; cursor: pointer; transition: background .15s; }
.context-menu-item:hover { background: #f5f7ff; }
.context-menu-item:last-child { color: #e74c3c; }

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: #bbb; }
