:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --primary: #4f6ef7;
  --primary-dark: #3b55d9;
  --text: #1f2937;
  --text-dim: #6b7280;
  --border: #e5e7eb;
  --sys: #9ca3af;
  --radius: 12px;
  --code-bg: #1e1e2e;
  --code-text: #e6e6e6;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}
.container {
  max-width: 90%;
  margin: 0 auto;
  padding: 24px 16px;
  height: 100%;
  display: flex;
  flex-direction: column;
}
h1 { font-size: 22px; margin: 0 0 4px; }
.subtitle { color: var(--text-dim); font-size: 13px; margin-bottom: 20px; }

/* ---------- 卡片 / 表单 ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; }
input[type="text"], input[type="password"] {
  flex: 1;
  min-width: 140px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
input:focus { border-color: var(--primary); }
button, .btn {
  padding: 9px 18px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--primary-dark); }
button:disabled { background: #c3cad8; cursor: not-allowed; }
button.ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}

/* ---------- 房间列表 ---------- */
.room-list { display: flex; flex-direction: column; gap: 8px; }
.room-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  cursor: pointer;
  transition: border-color .15s;
}
.room-item:hover { border-color: var(--primary); }
.room-item .name { font-weight: 600; font-size: 15px; flex: 1; }
.room-item .meta { color: var(--text-dim); font-size: 13px; display: flex; gap: 10px; align-items: center; }
.empty-tip { color: var(--text-dim); text-align: center; padding: 30px 0; font-size: 14px; }
.lock { font-size: 13px; }

/* ---------- 聊天页 ---------- */
.chat-container { max-width: 90%; padding: 12px 12px 0; height: 100vh; position: relative; }
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px 12px;
  border-bottom: 1px solid var(--border);
}
.chat-header .title { font-weight: 700; font-size: 16px; flex: 1; }
.chat-header .online { color: var(--text-dim); font-size: 13px; }
.back-link { color: var(--primary); text-decoration: none; font-size: 14px; }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
}
/* 翻历史时有新消息的提示条（悬浮在输入区上方） */
.new-msg-tip {
  position: absolute;
  bottom: 98px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  font-size: 12.5px;
  padding: 6px 16px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(79,110,247,.4);
  z-index: 10;
  animation: tip-in .18s ease-out;
}
.new-msg-tip:hover { background: var(--primary-dark); }
@keyframes tip-in {
  from { opacity: 0; transform: translateX(-50%) translateY(6px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.msg-row { display: flex; flex-direction: column; max-width: min(85%, 1100px); }
.msg-row.mine { align-self: flex-end; align-items: flex-end; }
.msg-row.other { align-self: flex-start; align-items: flex-start; }
.msg-row.sys { align-self: center; max-width: 100%; }
.msg-nick { font-size: 12px; color: var(--text-dim); margin: 0 4px 3px; }
/* 消息工具条：hover 气泡所在行时出现 */
.msg-row { position: relative; }
.msg-tools {
  position: absolute;
  top: -6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s;
  display: flex;
  gap: 4px;
  z-index: 5;
}
.msg-row.other .msg-tools { right: -8px; flex-direction: row; }
.msg-row.mine .msg-tools { left: -8px; flex-direction: row-reverse; }
.msg-row:hover .msg-tools {
  opacity: 1;
  pointer-events: auto;
}
.tool-btn {
  width: 24px; height: 24px;
  padding: 0;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tool-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--panel);
}
.msg-row.mine .tool-btn { background: #6b83f8; border-color: rgba(255,255,255,.4); color: #fff; }
.msg-row.mine .tool-btn:hover { background: #5a73f0; }
.bubble {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}
.msg-row.mine .bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg-row.other .bubble { background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-row.sys .bubble {
  background: transparent; border: none; color: var(--sys);
  font-size: 12px; padding: 2px 8px; white-space: normal; text-align: center;
}
.bubble img.chat-img {
  max-width: 300px;
  max-height: 260px;
  border-radius: 8px;
  display: block;
  cursor: zoom-in;
}
/* 双击复制反馈 */
.bubble.copied { outline: 2px solid #22c55e; outline-offset: 1px; }
.bubble.copy-fail { outline: 2px solid #dc2626; outline-offset: 1px; }
.copy-flash {
  position: absolute;
  top: -12px;
  right: 8px;
  background: #22c55e;
  color: #fff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  pointer-events: none;
  animation: tip-in .15s ease-out;
  z-index: 5;
}
.copy-flash { top: -10px; }
.compress-tag { font-size: 11px; opacity: .75; margin-top: 4px; }

/* ---------- 代码块 ---------- */
.bubble pre.code-block, pre.code-block {
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 6px 0 2px;
  overflow-x: auto;
  font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre;
  max-width: 100%;   /* 跟随气泡宽度，长行横向滚动 */
}
.msg-row.mine pre.code-block .code-lang { color: #9ca8d4; }
.code-lang {
  display: block;
  font-size: 10.5px;
  color: #9ca8d4;
  margin-bottom: 4px;
  font-family: system-ui, sans-serif;
}
/* 代码高亮配色（highlight.js 自定义主题，VSCode Dark+ 风格） */
.code-block code { font: inherit; color: var(--code-text); white-space: pre; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-section, .hljs-doctag, .hljs-type, .hljs-name, .hljs-strong {
  color: #c586c0;
}
.hljs-string, .hljs-title.class_, .hljs-title.class_.inherited__, .hljs-attribute, .hljs-symbol, .hljs-bullet, .hljs-addition, .hljs-code, .hljs-template_tag, .hljs-variable {
  color: #ce9178;
}
.hljs-title, .hljs-title.function_, .hljs-function .hljs-title, .hljs-subst {
  color: #dcdcaa;
}
.hljs-comment, .hljs-quote, .hljs-deletion, .hljs-meta {
  color: #6a9955;
  font-style: italic;
}
.hljs-number, .hljs-regexp, .hljs-link {
  color: #b5cea8;
}
.hljs-built_in, .hljs-builtin-name, .hljs-class .hljs-title {
  color: #4ec9b0;
}
.hljs-attr, .hljs-property, .hljs-params {
  color: #9cdcfe;
}
.hljs-tag { color: #808080; }
.hljs-emphasis { font-style: italic; }
.code-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 11px;
  padding: 2px 8px;
  background: rgba(255,255,255,.14);
  color: #dcdcdc;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}
.code-copy-btn:hover { background: rgba(255,255,255,.28); }
.msg-row.mine .code-copy-btn { background: rgba(0,0,0,.25); color: #fff; }

/* ---------- 右键菜单 ---------- */
.ctx-menu {
  position: fixed;
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 4px;
  min-width: 130px;
}
.ctx-menu .item {
  padding: 7px 14px;
  font-size: 13.5px;
  border-radius: 6px;
  cursor: pointer;
}
.ctx-menu .item:hover { background: var(--bg); }

/* ---------- 输入区 ---------- */
.input-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 0 14px;
}
#msgInput {
  flex: 1;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  height: 38px;
  min-height: 38px;
  max-height: 300px;
  resize: none;
  overflow-y: auto;
  line-height: 1.45;
  display: block;
}
/* 内容较长时输入框增高，圆角跟随变化 */
#msgInput.tall {
  border-radius: 14px;
  line-height: 1.45;
}
#msgInput:focus { border-color: var(--primary); }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  padding: 0;
  font-size: 17px;
  background: var(--panel);
  color: var(--text-dim);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.icon-btn:hover { color: var(--primary); border-color: var(--primary); background: var(--panel); }
.input-tip { font-size: 11px; color: var(--sys); text-align: right; padding: 0 8px 10px; }
.status-bar {
  font-size: 12px;
  color: var(--text-dim);
  padding: 2px 8px 6px;
  min-height: 18px;
}
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
}
.overlay img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }
.dialog-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 600;
}
.dialog {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  width: 320px;
}
.dialog h3 { margin: 0 0 12px; font-size: 15px; }
.dialog .form-row { flex-direction: column; }
.dialog .err { color: #dc2626; font-size: 12.5px; min-height: 16px; margin-top: 8px; }

@media (max-width: 560px) {
  .msg-row { max-width: 92%; }
}
