* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: #eef1f8;
  color: #1f2937;
  overflow: hidden;
}
button, input, textarea { font-family: inherit; }
.hidden { display: none !important; }

.app { height: 100vh; display: flex; flex-direction: column; }

/* ---------- 顶部栏 ---------- */
.topbar {
  height: 62px;
  flex: 0 0 62px;
  background: #fff;
  border-bottom: 1px solid #e6e9f2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: 0 2px 10px rgba(30,40,90,.03);
  z-index: 5;
}
.logo { font-size: 18px; font-weight: 700; color: #312e81; display: flex; align-items: center; gap: 10px; }
.logo-mark { color: #4f46e5; font-size: 24px; }
.me-area { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.me-name { font-weight: 600; color: #374151; }
.me-status { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; display: inline-block; }
.logout {
  border: 1px solid #e0e3ee; background: #fff; color: #6b7280;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.logout:hover { background: #f9fafb; color: #dc2626; border-color: #fecaca; }

/* ---------- 主体布局 ---------- */
.main { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 320px;
  flex: 0 0 320px;
  background: #fff;
  border-right: 1px solid #e6e9f2;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.search-box { padding: 16px; display: flex; gap: 8px; }
.search-box input {
  flex: 1; min-width: 0; height: 38px; border: 1px solid #dfe2ee; border-radius: 9px;
  padding: 0 12px; font-size: 13px; outline: none;
}
.search-box input:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
.search-box button {
  border: 0; background: #4f46e5; color: #fff; border-radius: 9px;
  padding: 0 16px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.search-box button:hover { background: #4338ca; }

.side-tabs { display: flex; border-bottom: 1px solid #eef0f6; padding: 0 16px; }
.side-tab {
  padding: 10px 14px; font-size: 13px; color: #8a90a6; cursor: pointer;
  border-bottom: 2px solid transparent; font-weight: 600;
}
.side-tab.active { color: #4f46e5; border-bottom-color: #4f46e5; }

.side-list { flex: 1; overflow-y: auto; }
.contact {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px;
  cursor: pointer; border-bottom: 1px solid #f4f5fa; transition: background .15s;
}
.contact:hover { background: #f8f9ff; }
.contact.active { background: #eef2ff; }
.avatar {
  width: 44px; height: 44px; flex: 0 0 44px; border-radius: 12px;
  background: linear-gradient(135deg,#818cf8,#4f46e5); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 600; position: relative; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.dot {
  position: absolute; right: 0; bottom: 0; width: 11px; height: 11px;
  border-radius: 50%; background: #cbd5e1; border: 2px solid #fff;
}
.dot.online { background: #22c55e; }
.contact-body { flex: 1; min-width: 0; }
.contact-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.contact-name { font-size: 14px; font-weight: 600; color: #1f2937; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-time { font-size: 11px; color: #a1a6b8; flex: 0 0 auto; }
.contact-preview { font-size: 12px; color: #9ca3af; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread {
  background: #ef4444; color: #fff; font-size: 11px; min-width: 18px; height: 18px;
  border-radius: 9px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center;
}
.side-empty { padding: 40px 20px; text-align: center; color: #a1a6b8; font-size: 13px; line-height: 1.8; }

/* ---------- 聊天区 ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #f7f8fc; }
.chat-header {
  height: 62px; flex: 0 0 62px; background: #fff; border-bottom: 1px solid #e6e9f2;
  display: flex; align-items: center; padding: 0 24px;
}
.chat-header .placeholder { color: #a1a6b8; font-size: 14px; }
.back-btn { display: none; }
.peer-head { display: flex; align-items: center; gap: 12px; }
.peer-head .avatar { width: 38px; height: 38px; flex-basis: 38px; font-size: 15px; border-radius: 10px; }
.peer-title { font-size: 15px; font-weight: 700; }
.peer-sub { font-size: 12px; color: #9ca3af; margin-top: 2px; }
.peer-sub .on { color: #16a34a; }

.messages { flex: 1; overflow-y: auto; padding: 22px 28px; }
.empty-hint { text-align: center; color: #9ca3af; margin-top: 22vh; font-size: 14px; }
.empty-icon { font-size: 44px; color: #c7d2fe; margin-bottom: 12px; }
.empty-hint .sub { font-size: 12px; color: #c0c5d2; margin-top: 8px; }

.msg { display: flex; flex-direction: column; margin-bottom: 18px; max-width: 68%; }
.msg.mine { margin-left: auto; align-items: flex-end; }
.msg.theirs { margin-right: auto; align-items: flex-start; }
.bubble {
  background: #fff; padding: 11px 15px; border-radius: 14px 14px 14px 4px;
  font-size: 14px; line-height: 1.6; box-shadow: 0 2px 8px rgba(30,40,90,.05);
  word-break: break-word; white-space: pre-wrap;
}
.mine .bubble { background: linear-gradient(135deg,#6366f1,#4f46e5); color: #fff; border-radius: 14px 14px 4px 14px; }
.msg .time { font-size: 11px; color: #b0b5c4; margin-top: 6px; }
.chat-img { max-width: 260px; max-height: 260px; border-radius: 8px; display: block; }
.file-link {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
  background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.35);
  padding: 8px 12px; border-radius: 8px;
}
.theirs .file-link { background: #f3f4f8; border-color: #e5e7ef; color: #374151; }
.sys-msg { color: #8a90a6; font-style: italic; font-size: 13px; }

.composer { flex: 0 0 auto; background: #fff; border-top: 1px solid #e6e9f2; padding: 12px 20px 16px; }
.tools { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.tool {
  border: 1px solid #e5e7ef; background: #fff; color: #4b5563; border-radius: 8px;
  padding: 6px 12px; font-size: 12px; cursor: pointer;
}
.tool:hover { border-color: #a5b4fc; color: #4f46e5; background: #f8f9ff; }
.call-tool { color: #4338ca; font-weight: 600; }
.tool-sep { width: 1px; height: 20px; background: #e5e7ef; margin: 0 4px; }
.input-row { display: flex; gap: 10px; align-items: flex-end; }
.input-row textarea {
  flex: 1; resize: none; border: 1px solid #dfe2ee; border-radius: 10px;
  padding: 10px 12px; font-size: 14px; outline: none; line-height: 1.5; max-height: 120px;
}
.input-row textarea:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.1); }
.send-btn {
  height: 42px; padding: 0 22px; border: 0; border-radius: 10px;
  background: linear-gradient(135deg,#4f46e5,#6366f1); color: #fff;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.send-btn:hover { filter: brightness(1.08); }

/* ---------- 来电弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,18,40,.55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.incoming-card {
  width: 330px; background: #fff; border-radius: 20px; padding: 34px 30px;
  text-align: center; box-shadow: 0 24px 70px rgba(0,0,0,.25);
  animation: pop .25s ease;
}
@keyframes pop { from { transform: scale(.9); opacity: 0 } to { transform: scale(1); opacity: 1 } }
.ring-icon { font-size: 44px; animation: ring 1s infinite; }
@keyframes ring { 0%,100%{transform:rotate(0)} 25%{transform:rotate(-15deg)} 75%{transform:rotate(15deg)} }
.incoming-title { color: #6b7280; font-size: 13px; margin-top: 10px; }
.incoming-name { font-size: 24px; font-weight: 700; margin: 10px 0 4px; }
.incoming-type { font-size: 13px; color: #4f46e5; }
.incoming-actions { display: flex; gap: 14px; margin-top: 28px; }
.incoming-actions button { flex: 1; height: 44px; border: 0; border-radius: 11px; color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; }
.btn-reject { background: #ef4444; }
.btn-reject:hover { background: #dc2626; }
.btn-accept { background: #22c55e; }
.btn-accept:hover { background: #16a34a; }

/* ---------- 通话界面 ---------- */
.call-overlay { position: fixed; inset: 0; background: #0b1020; z-index: 60; display: flex; flex-direction: column; }
.call-top { padding: 20px 28px; color: #fff; display: flex; justify-content: space-between; align-items: flex-start; }
.call-title { font-size: 13px; color: #9aa4c0; }
.call-peer { font-size: 22px; font-weight: 700; margin-top: 4px; }
.call-timer { font-size: 14px; color: #a5b4fc; margin-top: 6px; font-variant-numeric: tabular-nums; }
.call-status { font-size: 13px; color: #fbbf24; background: rgba(251,191,36,.12); padding: 6px 14px; border-radius: 20px; }
.video-stage { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; }
#remoteVideo { width: 100%; height: 100%; object-fit: contain; background: #000; }
.audio-only { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: radial-gradient(circle at center,#1e2745,#0b1020); }
.big-avatar {
  width: 120px; height: 120px; border-radius: 50%; background: linear-gradient(135deg,#6366f1,#7c3aed);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 42px; font-weight: 600;
}
.audio-name { color: #fff; font-size: 18px; margin-top: 18px; }
.local-wrap {
  position: absolute; right: 24px; bottom: 24px; width: 220px; height: 160px;
  border-radius: 14px; overflow: hidden; border: 2px solid rgba(255,255,255,.22);
  background: #111827; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.local-wrap video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.local-label { position: absolute; left: 8px; bottom: 6px; color: #fff; font-size: 11px; background: rgba(0,0,0,.45); padding: 2px 7px; border-radius: 5px; }
.call-controls { display: flex; justify-content: center; gap: 22px; padding: 24px 0 34px; }
.ctrl {
  width: 74px; border: 0; background: transparent; color: #d1d5db; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 7px;
}
.ctrl-icon {
  width: 54px; height: 54px; border-radius: 50%; background: #242c45;
  display: flex; align-items: center; justify-content: center; font-size: 21px; transition: .15s;
}
.ctrl:hover .ctrl-icon { background: #333d5c; }
.ctrl.off .ctrl-icon { background: #4b5563; opacity: .6; }
.ctrl-label { font-size: 12px; }
.ctrl.hangup .ctrl-icon { background: #ef4444; }
.ctrl.hangup:hover .ctrl-icon { background: #dc2626; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: 78px; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; padding: 11px 20px; border-radius: 10px;
  font-size: 13px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}

@media (max-width: 720px) {
  .back-btn { display: block; border: 0; background: none; color: #4f46e5; font-size: 30px; line-height: 1; margin-right: 12px; cursor: pointer; }
  .sidebar { width: 100%; flex-basis: 100%; }
  .chat { display: none; }
  .sidebar.mobile-hide { display: none; }
  .chat.mobile-show { display: flex; position: fixed; inset: 62px 0 0 0; z-index: 10; }
  .local-wrap { width: 130px; height: 100px; }
}
