:root {
  --bg: #11141f;
  --panel: #181c30;
  --panel-2: #1f2540;
  --line: #2a3152;
  --text: #e8ecf8;
  --muted: #8b93b5;
  --accent: #6384ff;
  --accent-2: #4a5fd0;
  --owner: #ffcc66;
  --intern: #66d9a3;
  --cc: #7aa2ff;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

.dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff, var(--accent));
  box-shadow: 0 0 8px var(--accent);
}

/* 登录 */
.login { display: flex; align-items: center; justify-content: center; height: 100%; padding: 24px; }
.card {
  width: 100%; max-width: 340px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 18px; padding: 28px 22px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.brand { font-size: 22px; font-weight: 700; letter-spacing: .5px; display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.card input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 13px 14px; font-size: 16px; outline: none;
}
.card input:focus { border-color: var(--accent); }
.card button, .send {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #fff; border: none; border-radius: 12px; padding: 13px; font-size: 16px;
  font-weight: 600; cursor: pointer;
}
.card button:active, .send:active { transform: translateY(1px); }
.error { color: var(--danger); font-size: 13px; min-height: 16px; text-align: center; }

/* 主视图 */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.room-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 44vw; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.ghost {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 7px 11px; font-size: 14px; cursor: pointer;
}
.ghost:active { background: var(--line); }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 700; text-transform: uppercase; }
.badge.owner { background: rgba(255,204,102,.16); color: var(--owner); }
.badge.intern { background: rgba(102,217,163,.16); color: var(--intern); }
.badge.cc { background: rgba(122,162,255,.16); color: var(--cc); }

/* thread */
.thread { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.msg .meta { font-size: 11px; color: var(--muted); margin: 0 4px 3px; display: flex; gap: 6px; align-items: center; }
.msg .bubble {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 9px 12px; white-space: pre-wrap; word-break: break-word;
}
.msg.mine .bubble { background: var(--panel-2); border-color: var(--accent-2); }
.msg .who { font-weight: 700; }
.msg .who.owner { color: var(--owner); }
.msg .who.intern { color: var(--intern); }
.msg .who.cc { color: var(--cc); }
.bubble.type-command { border-left: 3px solid var(--owner); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.bubble.type-result, .bubble.type-status { border-left: 3px solid var(--cc); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.bubble.type-system { background: transparent; border-style: dashed; color: var(--muted); font-size: 13px; }
.tag { font-size: 10px; padding: 1px 6px; border-radius: 6px; background: var(--line); color: var(--muted); }
.file a {
  color: var(--accent); text-decoration: none; display: inline-flex; gap: 6px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 11px; margin-top: 4px;
}
.file a:active { background: var(--line); }

/* composer */
.composer {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px);
  background: var(--panel); border-top: 1px solid var(--line);
}
.attach {
  width: 40px; height: 40px; flex: none; border-radius: 50%; background: var(--panel-2);
  border: 1px solid var(--line); display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: var(--accent); cursor: pointer; line-height: 1;
}
.msg-input {
  flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 20px; padding: 11px 14px; font-size: 16px; outline: none;
}
.msg-input:focus { border-color: var(--accent); }
.cmd-toggle { font-size: 12px; color: var(--owner); display: flex; align-items: center; gap: 3px; white-space: nowrap; }
.send { padding: 11px 16px; flex: none; }
.upload-status {
  position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; z-index: 9;
}

/* 暂存条（两步式上传） */
.staged-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--panel-2); border-top: 1px solid var(--line);
}
.staged-chip { display: inline-flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.staged-icon { flex: none; }
.staged-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.staged-size { color: var(--muted); font-size: 12px; flex: none; }
.staged-status { font-size: 12px; flex: none; }
.staged-clear {
  width: 28px; height: 28px; flex: none; border-radius: 50%; border: none;
  background: var(--line); color: var(--muted); font-size: 14px; cursor: pointer; line-height: 1;
}
.staged-clear:active { background: var(--panel); }
.staged-clear:disabled { opacity: .5; cursor: default; }
.staged-bar.staged-error { background: rgba(255,107,107,.10); border-top-color: var(--danger); }
.staged-bar.staged-error .staged-status { color: var(--danger); }
.send.sending { opacity: .7; pointer-events: none; }

/* 房间选择器 */
.room-picker { flex: 1; overflow-y: auto; display: flex; justify-content: center; padding: 24px 16px; }
.rp-card { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 12px; }
.rp-title { font-size: 18px; font-weight: 700; }
.rp-hint { font-size: 13px; color: var(--muted); line-height: 1.5; margin-bottom: 4px; }
.room-list { display: flex; flex-direction: column; gap: 8px; }
.room-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 14px 16px; font-size: 15px; cursor: pointer; text-align: left;
}
.room-item:active { background: var(--panel-2); }
.ri-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ri-kind { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: var(--line); color: var(--muted); flex: none; }
.ri-kind.ctrl { background: rgba(255,204,102,.16); color: var(--owner); }
.ri-kind.dm { background: rgba(102,217,163,.16); color: var(--intern); }
/* 未读角标：房间项右侧红胶囊（白字数字）*/
.ri-unread {
  flex: none; min-width: 20px; height: 20px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; line-height: 1;
  border-radius: 999px; background: #e5484d; color: #fff;
}
/* 顶部「房间」按钮上的总未读数（红点数字）*/
#switch-room { position: relative; }
#switch-room.has-unread::after {
  content: attr(data-count);
  position: absolute; top: -5px; right: -5px;
  min-width: 16px; height: 16px; padding: 0 4px; box-sizing: border-box;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; line-height: 1;
  border-radius: 999px; background: #e5484d; color: #fff;
}
.rl-section { font-size: 11px; color: var(--muted); font-weight: 700; letter-spacing: .5px; text-transform: uppercase; margin: 12px 4px 2px; }
.rl-section:first-child { margin-top: 2px; }
.rp-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 10px; }
.rp-create {
  margin-top: 8px; padding: 14px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; display: flex; flex-direction: column; gap: 9px;
}
.rp-create-title { font-size: 13px; color: var(--muted); font-weight: 600; }
.rp-input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 11px 12px; font-size: 15px; outline: none; width: 100%;
}
.rp-input:focus { border-color: var(--accent); }

.approval-toggle { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.approval-toggle input { width: 15px; height: 15px; accent-color: var(--accent); }

/* 操控 CC 房间提示条 */
.ctrl-hint {
  padding: 9px 14px calc(9px); font-size: 12px; line-height: 1.5;
  color: var(--owner); background: rgba(255,204,102,.09); border-top: 1px solid var(--line);
}

/* F2 自动优化按钮条 */
.improve-bar {
  display: flex; gap: 8px; padding: 8px 14px;
  background: rgba(99,132,255,.07); border-top: 1px solid var(--line);
}
.improve-bar .ghost { flex: 1; }

/* CC 消息的 Markdown 渲染（覆盖气泡 pre-wrap，块级正常排版） */
.bubble .md {
  white-space: normal; font-size: 15px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md li { margin: 2px 0; }
.md .md-h { font-weight: 700; margin: 10px 0 4px; color: var(--text); }
.md strong { font-weight: 700; }
.md a { color: var(--accent); }
.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px;
}
.md pre.md-pre {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin: 8px 0; overflow-x: auto;
}
.md pre.md-pre code { background: none; border: none; padding: 0; font-size: 13px; }
.md .md-table { border-collapse: collapse; margin: 8px 0; display: block; overflow-x: auto; font-size: 13px; }
.md .md-table th, .md .md-table td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.md .md-table th { background: var(--panel-2); font-weight: 700; }

/* status 紧凑提示行 */
.status-line { font-size: 12px; color: var(--muted); text-align: center; margin: 2px 0; }
