/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-page: #eef1f6;
  --bg-sidebar: #ffffff;
  --bg-chat: #f7f8fc;
  --bg-input: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f0f0f5;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --text: #1e1e2e;
  --text-dim: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --msg-mine: #6366f1;
  --msg-mine-text: #ffffff;
  --msg-peer: #ffffff;
  --msg-peer-text: #1e1e2e;
  --online: #22c55e;
  --danger: #ef4444;
  --radius: 16px;
  --radius-lg: 24px;
  --radius-xl: 28px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 8px 30px rgba(0,0,0,0.08);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-page);
}
input, textarea, button { font-family: inherit; font-size: inherit; }

/* ===== Enter Screen ===== */
.enter-screen {
  display: flex; align-items: center; justify-content: center; height: 100%;
  background: linear-gradient(135deg, #e8eaf6 0%, #f5f5f5 50%, #e3f2fd 100%);
}
.enter-card {
  background: var(--bg-card); border-radius: var(--radius-xl); padding: 36px;
  width: 400px; text-align: center; box-shadow: var(--shadow-md);
  overflow: visible; position: relative;
}
.enter-logo { font-size: 48px; margin-bottom: 8px; }
.enter-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; color: var(--text); }
.enter-subtitle { color: var(--text-dim); margin-bottom: 24px; }
.enter-form { display: flex; flex-direction: column; gap: 12px; }
.enter-form input {
  padding: 14px 16px; border-radius: 14px; border: 1px solid var(--border);
  background: #fafafa; color: var(--text); outline: none; font-size: 15px;
  transition: border-color 0.2s;
}
.enter-form input:focus { border-color: var(--primary); background: #fff; }

/* User list on enter screen */
.user-list-section { text-align: left; margin-bottom: 4px; }
.user-list-title {
  font-size: 12px; color: var(--text-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px;
}
.user-list {
  max-height: 200px; overflow-y: auto; border: 1px solid var(--border);
  border-radius: 14px; background: #fafafa;
}
.user-list-loading, .user-list-empty {
  padding: 16px; text-align: center; color: var(--text-muted); font-size: 13px;
}
.user-list-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  cursor: pointer; transition: background 0.15s; border-bottom: 1px solid var(--border);
}
.user-list-item:last-child { border-bottom: none; }
.user-list-item:hover { background: var(--primary-light); }
.user-list-item .ul-avatar {
  width: 32px; height: 32px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 13px;
  font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-list-item .ul-name { flex: 1; font-size: 14px; font-weight: 500; }
.user-list-item .ul-status { font-size: 11px; padding: 2px 8px; border-radius: 10px; }
.user-list-item .ul-status.online { background: #dcfce7; color: #166534; }
.user-list-item .ul-status.offline { background: #f3f4f6; color: #6b7280; }

.enter-divider {
  display: flex; align-items: center; gap: 12px; margin: 16px 0;
  color: var(--text-muted); font-size: 13px;
}
.enter-divider::before, .enter-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.btn-primary {
  padding: 14px; border-radius: 14px; border: none; background: var(--primary);
  color: #fff; font-weight: 600; font-size: 15px; cursor: pointer; transition: background 0.2s;
}
.btn-primary:hover { background: var(--primary-hover); }
.enter-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 20px; }

/* ===== Chat Screen Layout ===== */
.chat-screen {
  display: flex; height: 100%; background: var(--bg-page);
}

/* ===== Sidebar — fixed left, full height ===== */
.sidebar {
  width: 280px; min-width: 280px; background: var(--bg-sidebar);
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px; border-bottom: 1px solid var(--border);
}
.my-info { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.avatar-sm {
  width: 38px; height: 38px; border-radius: 50%; background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.icon-btn {
  width: 34px; height: 34px; border-radius: 12px; border: none; background: transparent;
  color: var(--text-dim); font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.sidebar-search {
  display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.sidebar-search input {
  flex: 1; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: #f5f6fa; color: var(--text); outline: none; font-size: 13px;
}
.sidebar-search input:focus { border-color: var(--primary); background: #fff; }
.section-title {
  padding: 12px 16px 6px; font-size: 11px; color: var(--text-muted);
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px;
}
.contact-list { flex: 1; overflow-y: auto; }
.contact-item {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  cursor: pointer; transition: background 0.15s;
}
.contact-item:hover { background: var(--bg-hover); }
.contact-item.active { background: var(--primary-light); }
.contact-avatar { position: relative; }
.contact-avatar .online-dot {
  position: absolute; bottom: 0; right: 0; width: 10px; height: 10px;
  border-radius: 50%; background: var(--text-muted); border: 2px solid var(--bg-sidebar);
}
.contact-avatar .online-dot.online { background: var(--online); }
.contact-info { flex: 1; min-width: 0; }
.contact-name {
  font-weight: 600; font-size: 14px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.contact-last-msg {
  font-size: 12px; color: var(--text-muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; margin-top: 2px;
}
.contact-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.contact-time { font-size: 11px; color: var(--text-muted); }
.unread-badge {
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
}

/* ===== Chat Main — centered 800px card with padding ===== */
.chat-main {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 28px; min-width: 0; background: var(--bg-page);
}
.chat-empty {
  width: 800px; max-width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; color: var(--text-muted);
  background: var(--bg-card); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
}
.empty-icon { font-size: 64px; margin-bottom: 16px; opacity: 0.35; }

.chat-window {
  display: flex; flex-direction: column;
  width: 800px; max-width: 100%; height: 100%;
  background: var(--bg-card); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md); overflow: hidden;
  position: relative;
}

.chat-header {
  padding: 16px 24px; background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}
.chat-peer-info { display: flex; align-items: center; gap: 12px; }
.peer-name { font-weight: 700; font-size: 16px; }
.peer-status { font-size: 12px; color: var(--text-muted); }
.peer-status.online { color: var(--online); }

/* Messages */
.chat-messages {
  flex: 1; overflow-y: auto; padding: 24px; display: flex;
  flex-direction: column; gap: 6px; background: var(--bg-chat);
}
.msg-row { display: flex; gap: 8px; max-width: 70%; }
.msg-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.peer { align-self: flex-start; }
.msg-bubble-wrap { display: flex; flex-direction: column; gap: 2px; }
.msg-reply-ref {
  font-size: 12px; color: var(--text-dim); background: rgba(0,0,0,0.03);
  padding: 4px 10px; border-radius: 10px; border-left: 3px solid var(--primary);
  max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
}
.msg-bubble {
  padding: 12px 16px; border-radius: 20px; line-height: 1.55;
  word-break: break-word; white-space: pre-wrap;
}
.msg-row.mine .msg-bubble {
  background: var(--msg-mine); color: var(--msg-mine-text);
  border-bottom-right-radius: 6px;
}
.msg-row.peer .msg-bubble {
  background: var(--msg-peer); color: var(--msg-peer-text);
  border-bottom-left-radius: 6px; box-shadow: var(--shadow-sm);
}
.msg-bubble img {
  max-width: 240px; max-height: 240px; border-radius: 14px; cursor: pointer; display: block;
}
.msg-time { font-size: 11px; color: var(--text-muted); align-self: flex-end; flex-shrink: 0; }
.msg-date-divider {
  text-align: center; color: var(--text-muted); font-size: 12px; padding: 10px 0;
}

/* Reply Bar */
.reply-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 24px; background: var(--primary-light);
}
.reply-bar-content { display: flex; align-items: center; gap: 8px; min-width: 0; }
.reply-bar-label { font-size: 12px; font-weight: 600; color: var(--primary); flex-shrink: 0; }
.reply-bar-text {
  font-size: 13px; color: var(--text-dim); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.reply-bar-close {
  background: none; border: none; font-size: 16px; color: var(--text-dim);
  cursor: pointer; padding: 4px; border-radius: 8px;
}
.reply-bar-close:hover { background: var(--bg-hover); }

/* Input Area — taller, rounded */
.chat-input-area {
  padding: 16px 24px 20px; background: var(--bg-card);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}
.input-toolbar { display: flex; gap: 4px; margin-bottom: 10px; }
.toolbar-btn {
  width: 36px; height: 36px; border-radius: 12px; border: none; background: transparent;
  font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.toolbar-btn:hover { background: var(--bg-hover); }
.input-row { display: flex; gap: 12px; align-items: flex-end; }
.input-row textarea {
  flex: 1; padding: 14px 18px; border-radius: 18px; border: 1px solid var(--border);
  background: #f5f6fa; color: var(--text); outline: none; resize: none;
  min-height: 80px; max-height: 140px; line-height: 1.5; font-size: 15px;
}
.input-row textarea:focus { border-color: var(--primary); background: #fff; }
.btn-send {
  padding: 14px 24px; border-radius: 18px; border: none; background: var(--primary);
  color: #fff; font-weight: 600; font-size: 15px; cursor: pointer;
  transition: background 0.2s; white-space: nowrap;
}
.btn-send:hover { background: var(--primary-hover); }

/* Emoji Picker */
.emoji-picker {
  position: absolute; bottom: 120px; left: 24px; width: 320px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow-md); z-index: 100; overflow: hidden;
}
.emoji-tabs {
  display: flex; border-bottom: 1px solid var(--border); overflow-x: auto;
  padding: 6px 6px 0;
}
.emoji-tab {
  padding: 6px 10px; font-size: 18px; cursor: pointer; border: none; background: none;
  border-bottom: 2px solid transparent; flex-shrink: 0; transition: all 0.15s;
  border-radius: 8px 8px 0 0;
}
.emoji-tab.active { border-bottom-color: var(--primary); background: var(--primary-light); }
.emoji-tab:hover { background: var(--bg-hover); }
.emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  padding: 10px; max-height: 200px; overflow-y: auto;
}
.emoji-item {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  font-size: 22px; cursor: pointer; border-radius: 10px; border: none; background: none;
  transition: background 0.15s;
}
.emoji-item:hover { background: var(--bg-hover); }

/* Context Menu */
.context-menu {
  position: fixed; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-md); z-index: 200; min-width: 140px;
  padding: 6px 0; overflow: hidden;
}
.context-item {
  padding: 10px 18px; cursor: pointer; font-size: 13px; transition: background 0.15s;
}
.context-item:hover { background: var(--bg-hover); }
.ctx-danger { color: #ef4444; }
.ctx-danger:hover { background: #fef2f2; }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* Toast */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  padding: 12px 28px; border-radius: 16px; font-size: 13px; font-weight: 500;
  z-index: 9999; animation: toastIn 0.3s ease; box-shadow: var(--shadow-md);
}
.toast.success { background: #dcfce7; color: #166534; }
.toast.error   { background: #fee2e2; color: #991b1b; }
.toast.info    { background: #dbeafe; color: #1e40af; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Image preview overlay */
.img-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 300;
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.img-overlay img { max-width: 90vw; max-height: 90vh; border-radius: 14px; }
