:root {
  --bg: #F6F5F1;
  --card: #FFFFFF;
  --ink: #1B1B19;
  --muted: #5E5D58;
  --line: #E4E2DC;
  --line-strong: #C9C6BD;
  --navy: #1F2A44;
  --claude: #A44B26;
  --gpt: #1D6E5D;
  --gemini: #2F5FC4;
  --opencode: #5F5E5A;
  --wait-bg: #F8E6DC;
  --wait-ink: #8A3A18;
  --ok-bg: #EEF3EC;
  --ok-ink: #2F5A2A;
  --run-bg: #E2F0EC;
  --run-ink: #1D5A4D;
  --chip-bg: #ECEAE4;
  --chip-ink: #3E3D3A;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--gemini); }
.muted { color: var(--muted); font-size: 13px; }
.error { color: #A32D2D; font-size: 13px; min-height: 18px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.row { display: flex; gap: 8px; }

.btn-primary {
  min-height: 44px; padding: 0 18px; border: none; border-radius: 10px;
  background: var(--navy); color: #fff; font-weight: 600;
}
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-ghost {
  min-height: 44px; padding: 0 16px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--card);
}
.icon-btn { width: 44px; height: 44px; border: none; background: transparent; display: flex; align-items: center; justify-content: center; }

/* Đăng nhập */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; display: flex; flex-direction: column; gap: 10px; }
.login-card h1 { font-size: 24px; font-weight: 600; }
.login-card label { font-size: 14px; font-weight: 500; margin-top: 8px; }
.login-card input { height: 46px; border: 1px solid var(--line-strong); border-radius: 10px; padding: 0 14px; background: var(--bg); }

/* Khung chính */
.app { display: flex; height: 100%; height: 100dvh; }
.sidebar {
  width: 280px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 20px 12px calc(16px + var(--safe-b)); gap: 8px; min-height: 0;
}
.side-head { padding: 4px 8px 4px; display: flex; flex-direction: column; gap: 2px; }
.side-head h1 { font-size: 22px; font-weight: 600; }
.team-status {
  margin: 4px 4px 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px;
  display: flex; align-items: center; gap: 10px; font-size: 13px;
}
.dot { width: 8px; height: 8px; border-radius: 4px; background: var(--line-strong); flex-shrink: 0; }
.dot.on { background: #3B7A34; }
.dot.wait { background: var(--claude); }
.project-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; min-height: 0; padding: 0 2px; }
.project {
  display: flex; flex-direction: column; gap: 5px; text-align: left; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.project:hover { border-color: var(--line-strong); }
.project.active { background: #EFEDE7; border-color: var(--line-strong); }
.project-top { display: flex; align-items: center; gap: 8px; }
.project-name { font-weight: 600; font-size: 14px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-last { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.project-time { font-size: 12px; color: var(--muted); }
.chip { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; white-space: nowrap; letter-spacing: .02em; }
.chip.wait { background: var(--wait-bg); color: var(--wait-ink); }
.chip.run { background: var(--run-bg); color: var(--run-ink); }
.chip.idle { background: var(--chip-bg); color: var(--chip-ink); }
.new-btn { width: 100%; }
.new-form { display: flex; flex-direction: column; gap: 6px; }
.new-form input { height: 44px; border: 1px solid var(--line-strong); border-radius: 10px; padding: 0 12px; background: var(--bg); }
.empty { padding: 24px 12px; color: var(--muted); font-size: 14px; text-align: center; }

/* Chat */
.chat { flex: 999 1 0; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.chat-head { background: var(--card); border-bottom: 1px solid var(--line); padding: 12px 20px; display: flex; align-items: center; gap: 8px; }
.chat-title { min-width: 0; }
.chat-title h2 { font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-btn { display: none; margin-left: -10px; }
.tabs { display: none; background: var(--card); border-bottom: 1px solid var(--line); padding: 0 16px; gap: 24px; }
.tab { border: none; background: none; padding: 10px 0; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--ink); }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.messages > * { max-width: 760px; }
.brief-mobile { flex: 1; overflow-y: auto; padding: 16px 20px; background: var(--card); min-height: 0; }

.msg { display: flex; gap: 10px; align-items: flex-start; }
.avatar { width: 32px; height: 32px; border-radius: 16px; color: #fff; font-size: 12px; font-weight: 600; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.msg-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.msg-meta { font-size: 12px; color: var(--muted); }
.msg-meta b { font-weight: 600; }
.bubble { background: var(--card); border: 1px solid var(--line); padding: 10px 14px; border-radius: 4px 16px 16px 16px; font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; max-width: min(80%, 620px); }
.msg.mine .msg-body { align-items: flex-end; }
.msg.mine .bubble { background: var(--navy); color: #fff; border-color: var(--navy); border-radius: 16px 16px 4px 16px; }
.msg.mine .bubble a { color: #C9DBFF; }
.msg.system .bubble { background: transparent; border-style: dashed; color: var(--muted); }

.conclusion { margin-left: 42px; background: var(--card); border: 1px solid var(--line-strong); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--claude); }
.conclusion .actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 4px; }
.conclusion .actions .btn-primary { flex: 1 1 120px; }
.decided { padding: 10px 12px; border-radius: 10px; background: var(--ok-bg); color: var(--ok-ink); font-size: 13px; font-weight: 500; }
.decided.no { background: var(--chip-bg); color: var(--chip-ink); }

.run-line { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding: 0 20px 10px 62px; }
.composer { background: var(--card); border-top: 1px solid var(--line); padding: 10px 12px calc(12px + var(--safe-b)); display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; min-width: 0; min-height: 44px; max-height: 160px; resize: none; border: 1px solid var(--line-strong); border-radius: 22px;
  padding: 11px 16px; background: var(--bg); line-height: 1.4; font-size: 15px;
}
.send-btn { width: 44px; height: 44px; border: none; border-radius: 22px; background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.send-btn:disabled { opacity: .5; }

/* Brief bên phải */
.brief-panel { width: 300px; flex-shrink: 0; background: var(--card); border-left: 1px solid var(--line); padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

/* Markdown gọn */
.md { font-size: 14px; line-height: 1.55; }
.md .h { font-weight: 600; margin-top: 10px; }
.md .h:first-child { margin-top: 0; }
.md .li { padding-left: 14px; position: relative; }
.md .li::before { content: '•'; position: absolute; left: 2px; color: var(--muted); }
.md code { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; background: rgba(0,0,0,.06); padding: 1px 4px; border-radius: 4px; }
.msg.mine .md code { background: rgba(255,255,255,.15); }
.md .wl { color: var(--gemini); }
.md .gap { height: 6px; }

/* Điện thoại */
@media (max-width: 1100px) {
  .brief-panel { display: none; }
  .tabs { display: flex; }
}
@media (max-width: 760px) {
  .sidebar { width: 100%; border-right: none; }
  .chat { display: none; }
  .app.view-chat .sidebar { display: none; }
  .app.view-chat .chat { display: flex; }
  .back-btn { display: flex; }
  .chat-head { padding: 10px 16px; }
  .messages { padding: 16px; }
  .conclusion { margin-left: 0; }
  .run-line { padding-left: 16px; }
}

/* Màu từng thành viên */
.p-claude { background: var(--claude); } .c-claude { color: var(--claude); }
.p-gpt { background: var(--gpt); } .c-gpt { color: var(--gpt); }
.p-gemini { background: var(--gemini); } .c-gemini { color: var(--gemini); }
.p-opencode { background: var(--opencode); } .c-opencode { color: var(--opencode); }
.p-khoa { background: var(--navy); } .c-khoa { color: var(--navy); }
