:root {
  --bg: #0e0f13; --panel: #13151b; --line: #232634;
  --text: #e6e6e6; --sub: #8ea0b8; --primary: #2a7cff;
  --bubble-me: #1e40af; --bubble-other: #1f2937;
  --sidebar-w: 280px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body { margin: 0; font-family: -apple-system, sans-serif; background: var(--bg); color: var(--text); height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }

.app-shell { display: flex; width: 100%; height: 100%; max-width: 1200px; margin: 0 auto; background: var(--panel); position: relative; }

.sidebar { width: var(--sidebar-w); border-right: 1px solid var(--line); display: flex; flex-direction: column; background: #0b0d12; z-index: 2; }
.my-card { padding: 16px; border-bottom: 1px solid var(--line); background: #0e1016; }
.my-info { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, #2a7cff, #00c6ff); display: grid; place-items: center; font-weight: bold; color: #fff; font-size: 18px; flex-shrink: 0; }
.my-name { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-row { display: flex; gap: 8px; font-size: 12px; color: var(--sub); align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #666; }
.dot.online { background: #22c55e; box-shadow: 0 0 8px #22c55e; }

.contact-list { flex: 1; overflow-y: auto; padding: 8px; }
.contact-item { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 8px; cursor: pointer; transition: .2s; margin-bottom: 4px; }
.contact-item:active, .contact-item.active { background: #1f232e; }
.c-info { flex: 1; min-width: 0; }
.c-top { display: flex; justify-content: space-between; margin-bottom: 4px; align-items: center; }
.c-name { font-size: 14px; font-weight: 500; color: #fff; display: flex; align-items: center; }
.c-time { font-size: 11px; color: #555; }

.unread-badge { background: #ff3b30; color: white; padding: 1px 6px; border-radius: 10px; font-size: 10px; margin-left: 6px; font-weight: bold; min-width: 18px; text-align: center; }

.chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); position: relative; }
.chat-header { height: 56px; border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 0 16px; background: var(--panel); justify-content: space-between; }
.ch-title { font-weight: 600; font-size: 16px; }
.ch-status { font-size: 12px; color: var(--sub); margin-left: 8px; font-weight: normal; }
.btn-icon { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; cursor: pointer; color: var(--sub); }

.msg-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }

.msg-row { display: flex; gap: 8px; max-width: 85%; }
.msg-row.me { align-self: flex-end; flex-direction: row-reverse; }

.msg-row > div { display: flex; flex-direction: column; }
.msg-row.me > div { align-items: flex-end; }
.msg-row.other > div { align-items: flex-start; }

.msg-bubble { 
  padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.4; 
  word-break: break-word; position: relative; 
  width: fit-content; min-width: 20px;
  /* 修复：显式允许文本选择 */
  user-select: text; -webkit-user-select: text;
}
.msg-row.me .msg-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg-row.other .msg-bubble { background: var(--bubble-other); color: #e5e7eb; border-bottom-left-radius: 4px; }

.msg-meta { font-size: 10px; opacity: 0.6; margin-top: 4px; text-align: right; }
.sys-msg { align-self: center; background: rgba(255,255,255,0.05); padding: 4px 12px; border-radius: 99px; font-size: 12px; color: var(--sub); }

.chat-img { max-width: 200px; border-radius: 8px; margin-top: 4px; cursor: pointer; display: block; }

.send-box { min-height: 60px; border-top: 1px solid var(--line); background: var(--panel); padding: 10px; display: flex; align-items: flex-end; gap: 10px; }
.input-wrap { flex: 1; background: #0a0c10; border: 1px solid #2b3040; border-radius: 20px; min-height: 40px; display: flex; align-items: center; padding: 4px 12px; }
#editor { flex: 1; max-height: 100px; overflow-y: auto; outline: none; font-size: 15px; line-height: 1.4; user-select: text; -webkit-user-select: text; }
#editor:empty:before { content: '发送消息...'; color: #555; }
.send-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--primary); color: #fff; border: none; display: grid; place-items: center; flex-shrink: 0; cursor: pointer; }

@media (max-width: 768px) {
  .sidebar { position: absolute; height: 100%; transform: translateX(0); transition: transform .3s; width: 100%; }
  .sidebar.hidden { transform: translateX(-100%); }
  .chat-area { width: 100%; }
  .mobile-back { display: block; margin-right: 8px; }
}
@media (min-width: 769px) {
  .mobile-back { display: none; }
  .sidebar.hidden { display: flex; transform: none; } 
}

#settings-panel { position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 99; display: none; place-items: center; }
.settings-box { width: 90%; max-width: 400px; background: #13151b; border-radius: 16px; padding: 20px; border: 1px solid var(--line); }
.st-input { width: 100%; padding: 10px; background: #0a0c10; border: 1px solid #2b3040; border-radius: 8px; color: #fff; font-size: 16px; margin-bottom: 15px; }
.st-btn { width: 100%; padding: 12px; border-radius: 8px; border: none; font-weight: 600; cursor: pointer; background: #2a7cff; color: #fff; }

.mini-log { 
  position: absolute; top: 60px; right: 10px; width: 240px; height: 260px; 
  background: rgba(0,0,0,0.95); color: #0f0; font-family: monospace; font-size: 10px; 
  border-radius: 8px; border: 1px solid #333;
  z-index: 99; display: none; flex-direction: column;
}
.log-bar { padding: 4px; border-bottom: 1px solid #333; display: flex; justify-content: flex-end; background: #111; }
.log-btn { background: #333; color: #fff; border: 1px solid #555; border-radius: 4px; padding: 2px 8px; font-size: 10px; cursor: pointer; }
.log-content { flex: 1; overflow: auto; padding: 8px; white-space: pre-wrap; user-select: text; -webkit-user-select: text; }