:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f0f0f2;
  --text: #1c1c1f;
  --muted: #6b6b76;
  --line: #e3e3e8;
  --accent: #5b5bd6;
  --accent-soft: #eeeefb;
  --ai: #0f7b6c;
  --ai-soft: #e6f4f1;
  --danger: #c0392b;
  --radius: 12px;
  --sidebar: 280px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171a;
    --surface: #202024;
    --surface-2: #2a2a30;
    --text: #ececf1;
    --muted: #9a9aa5;
    --line: #33333c;
    --accent: #8b8bf0;
    --accent-soft: #2a2a45;
    --ai: #4fd1b8;
    --ai-soft: #1c332f;
    --danger: #e06c5b;
  }
}

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

/* ── login ─────────────────────────────────────────────────────────────── */
#login {
  display: grid; place-items: center; height: 100vh; padding: 24px;
}
.login-card {
  width: min(380px, 100%); background: var(--surface); padding: 32px;
  border-radius: var(--radius); border: 1px solid var(--line);
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; letter-spacing: -0.02em; }
.login-card .sub { color: var(--muted); font-size: 14px; margin: 0 0 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=password], textarea, select {
  width: 100%; padding: 10px 12px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.btn {
  padding: 10px 16px; border-radius: 8px; border: 1px solid transparent;
  background: var(--accent); color: #fff; font-weight: 500;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ── shell ─────────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

#sidebar {
  width: var(--sidebar); flex: none; background: var(--surface);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
}
.side-head {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
}
.brand { font-weight: 600; letter-spacing: -0.01em; margin-right: auto; }
.side-actions { padding: 12px; display: flex; gap: 8px; }
.side-actions .btn { flex: 1; font-size: 14px; padding: 8px; }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px 16px; }
.conv {
  padding: 10px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 2px;
  display: flex; gap: 10px; align-items: flex-start;
}
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--accent-soft); }
.conv-icon { flex: none; width: 20px; text-align: center; opacity: .7; }
.conv-body { min-width: 0; flex: 1; }
.conv-title {
  font-size: 14px; font-weight: 500; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.conv-last {
  font-size: 12px; color: var(--muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; margin-top: 2px;
}
.side-foot {
  padding: 12px 16px; border-top: 1px solid var(--line);
  font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px;
}

/* ── main ──────────────────────────────────────────────────────────────── */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; background: var(--surface);
  min-height: 56px;
}
.topbar h2 {
  margin: 0; font-size: 16px; font-weight: 600; margin-right: auto;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar select { width: auto; padding: 6px 8px; font-size: 13px; }
.icon-btn {
  background: none; border: 1px solid var(--line); border-radius: 8px;
  width: 34px; height: 34px; display: grid; place-items: center; flex: none;
}
.icon-btn:hover { background: var(--surface-2); }
#menu-btn { display: none; }

.members { font-size: 12px; color: var(--muted); padding: 6px 16px;
  border-bottom: 1px solid var(--line); background: var(--surface); }

.messages { flex: 1; overflow-y: auto; padding: 20px 16px; }
.msg { max-width: 760px; margin: 0 auto 18px; display: flex; gap: 12px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.msg.ai .avatar { background: var(--ai-soft); color: var(--ai); }
.msg-body { min-width: 0; flex: 1; }
.msg-head { font-size: 13px; margin-bottom: 3px; }
.msg-head b { font-weight: 600; }
.msg-head span { color: var(--muted); margin-left: 8px; font-size: 11px; }
.msg-text { white-space: pre-wrap; word-wrap: break-word; }
.msg-text code {
  background: var(--surface-2); padding: 1px 5px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
}
.msg-text pre {
  background: var(--surface-2); padding: 12px; border-radius: 8px;
  overflow-x: auto; font-size: 13px;
}
.msg.system { justify-content: center; }
.msg.system .msg-text {
  font-size: 12.5px; color: var(--muted); background: var(--surface-2);
  padding: 6px 12px; border-radius: 999px; text-align: center;
}
.msg.system .avatar, .msg.system .msg-head { display: none; }

.agent-status {
  max-width: 760px; margin: 0 auto 18px; font-size: 13px; color: var(--ai);
  display: flex; align-items: center; gap: 8px;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%; background: currentColor;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: .3 } 50% { opacity: 1 } }

.composer {
  border-top: 1px solid var(--line); padding: 12px 16px; background: var(--surface);
}
.composer-inner { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; max-height: 160px; min-height: 42px; padding: 10px 12px;
  border-radius: 10px; background: var(--bg);
}
.hint { max-width: 760px; margin: 6px auto 0; font-size: 12px; color: var(--muted); }
.hint code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ── dashboard ─────────────────────────────────────────────────────────── */
.dash { flex: 1; overflow-y: auto; padding: 24px 16px; }
.dash-inner { max-width: 860px; margin: 0 auto; display: grid; gap: 24px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel h3 {
  margin: 0; padding: 14px 16px; font-size: 14px; font-weight: 600;
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px;
}
.panel h3 .count {
  background: var(--accent-soft); color: var(--accent); font-size: 12px;
  padding: 1px 8px; border-radius: 999px;
}
.panel-body { padding: 8px 16px 16px; }
.empty { color: var(--muted); font-size: 14px; padding: 16px 0; text-align: center; }

.task { display: flex; align-items: flex-start; gap: 10px; padding: 9px 0;
  border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
.task input[type=checkbox] { width: 17px; height: 17px; margin-top: 2px; flex: none;
  accent-color: var(--accent); cursor: pointer; }
.task-title { flex: 1; min-width: 0; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.task-del { background: none; border: 0; color: var(--muted); font-size: 16px; padding: 0 4px; }
.task-del:hover { color: var(--danger); }
.add-task { display: flex; gap: 8px; padding-top: 12px; }

.mail { padding: 11px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.mail:last-child { border-bottom: 0; }
.mail:hover .mail-subject { color: var(--accent); }
.mail-subject { font-weight: 500; font-size: 14px; }
.mail-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mail-preview { font-size: 12.5px; color: var(--muted); margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.notice { font-size: 13px; color: var(--muted); padding: 14px 0; }

/* ── modal ─────────────────────────────────────────────────────────────── */
.backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50;
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: min(460px, 100%); background: var(--surface); border-radius: var(--radius);
  padding: 22px; max-height: 88vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 16px; font-size: 17px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.people { display: grid; gap: 4px; max-height: 190px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.person { display: flex; align-items: center; gap: 9px; padding: 5px; border-radius: 6px; }
.person:hover { background: var(--surface-2); }
.person input { width: 16px; height: 16px; accent-color: var(--accent); }
.seg { display: flex; gap: 8px; margin-bottom: 14px; }
.seg button {
  flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent;
}
.seg button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.files-strip { display: flex; flex-wrap: wrap; gap: 6px; max-width: 760px;
  margin: 0 auto 8px; }
.chip {
  font-size: 12px; background: var(--surface-2); padding: 3px 9px;
  border-radius: 999px; display: inline-flex; align-items: center; gap: 6px;
}
.chip button { background: none; border: 0; color: var(--muted); padding: 0; font-size: 14px; }

/* ── mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  #menu-btn { display: grid; }
  #sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40; width: 84vw; max-width: 320px;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.2);
  }
  #sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; }
  .messages { padding: 14px 12px; }
  .composer { padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .dash { padding: 16px 12px; }
}
