/* ── 基础 ─────────────────────────────────────────────── */
:root {
  --bg:        #0d1117;
  --bg-soft:   #161b22;
  --bg-elev:   #1c2128;
  --border:    #30363d;
  --text:      #e6edf3;
  --text-dim:  #8b949e;
  --text-mute: #6e7681;
  --accent:    #2f81f7;
  --accent-dim:#1f6feb;
  --ok:        #3fb950;
  --warn:      #d29922;
  --danger:    #f85149;
  --radius:    10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
          "PingFang SC", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button { cursor: pointer; border: none; background: none; }

[hidden] { display: none !important; }

/* ── 登录页 ───────────────────────────────────────────── */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, #1a2332 0%, transparent 70%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 12px var(--ok);
}

.brand h1 { font-size: 17px; font-weight: 600; letter-spacing: .3px; }

.brand-sub {
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: -8px;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.login-card input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color .15s;
}

.login-card input:focus { border-color: var(--accent); }

.login-card button[type="submit"] {
  margin-top: 4px;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-radius: 8px;
  transition: background .15s;
}

.login-card button[type="submit"]:hover { background: var(--accent-dim); }
.login-card button[type="submit"]:disabled { opacity: .55; cursor: default; }

.err {
  font-size: 12.5px;
  color: var(--danger);
  background: rgba(248,81,73,.09);
  border: 1px solid rgba(248,81,73,.25);
  border-radius: 8px;
  padding: 8px 10px;
}

/* ── 聊天布局 ─────────────────────────────────────────── */
.chat-layout {
  display: grid;
  grid-template-columns: 268px 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ── 侧栏 ─────────────────────────────────────────────── */
.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.me {
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 8px;
  border-radius: 6px;
  transition: .15s;
}
.icon-btn:hover { background: var(--bg-elev); color: var(--text); }

.new-conv {
  margin: 12px 12px 8px;
  padding: 9px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 13px;
  transition: .15s;
}
.new-conv:hover { border-color: var(--accent); color: var(--accent); }

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
  min-height: 0;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s;
}
.conv-item:hover { background: var(--bg-elev); }
.conv-item.active { background: rgba(47,129,247,.13); }

.conv-item .t {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.conv-item .del {
  opacity: 0;
  font-size: 15px;
  color: var(--text-mute);
  padding: 0 3px;
  transition: .15s;
}
.conv-item:hover .del { opacity: 1; }
.conv-item .del:hover { color: var(--danger); }

.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-dim);
}

.status-chip { display: inline-flex; align-items: center; gap: 6px; }

.status-chip .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-mute);
  transition: background .3s, box-shadow .3s;
}
.status-chip.online .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status-chip.offline .dot { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.status-chip.busy .dot { background: var(--warn); box-shadow: 0 0 8px var(--warn); }

.queue-info { color: var(--text-mute); }

/* ── 主区 ─────────────────────────────────────────────── */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.main-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}

.main-head h2 {
  font-size: 14.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 46vw;
}

.persona-tag {
  font-size: 11.5px;
  color: var(--text-mute);
}

.offline-banner {
  font-size: 12px;
  color: var(--warn);
  background: rgba(210,153,34,.1);
  border: 1px solid rgba(210,153,34,.28);
  border-radius: 20px;
  padding: 4px 12px;
  white-space: nowrap;
}

/* ── 消息流 ───────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 22px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  scroll-behavior: smooth;
}

.empty-hint {
  margin: auto;
  color: var(--text-mute);
  font-size: 13px;
}

.msg {
  display: flex;
  gap: 10px;
  max-width: min(760px, 88%);
  animation: fadeUp .22s ease-out;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.msg.user { align-self: flex-end; flex-direction: row-reverse; }

.avatar {
  flex: 0 0 28px;
  width: 28px; height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  user-select: none;
}

.msg.user .avatar { background: rgba(47,129,247,.2); color: #79c0ff; }
.msg.assistant .avatar { background: rgba(63,185,80,.16); color: #7ee787; }

.bubble {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.65;
}

.msg.user .bubble {
  background: rgba(47,129,247,.14);
  border-color: rgba(47,129,247,.3);
}

/* 排队中的影子气泡 */
.bubble.ghost {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text-dim);
  font-size: 13px;
  font-style: normal;
}

.ghost .spin {
  width: 12px; height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex: 0 0 auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.bubble.failed {
  color: var(--danger);
  border-color: rgba(248,81,73,.35);
  background: rgba(248,81,73,.08);
  font-size: 13px;
}

/* ── 输入区 ───────────────────────────────────────────── */
.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 160px;
  padding: 11px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  line-height: 1.55;
  transition: border-color .15s;
}

.composer textarea:focus { border-color: var(--accent); }

.send-btn {
  padding: 11px 20px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-radius: 10px;
  transition: .15s;
}
.send-btn:hover:not(:disabled) { background: var(--accent-dim); }
.send-btn:disabled { opacity: .4; cursor: default; }

/* ── 弹窗 ─────────────────────────────────────────────── */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.62);
  display: grid;
  place-items: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}

.modal {
  width: min(340px, 92vw);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal h3 { font-size: 15px; font-weight: 600; }

.modal label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.modal select {
  padding: 9px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.modal-actions button {
  padding: 9px 18px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  background: var(--accent);
  color: #fff;
}

.modal-actions .ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}

/* ── 滚动条 ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #2b323c;
  border-radius: 5px;
  border: 2px solid var(--bg-soft);
}
::-webkit-scrollbar-thumb:hover { background: #3b444f; }

/* ── 移动端 ───────────────────────────────────────────── */
@media (max-width: 720px) {
  .chat-layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 32% 0 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .sidebar.open { transform: none; box-shadow: 12px 0 40px rgba(0,0,0,.6); }
  .main-head h2 { max-width: 60vw; }
  .messages { padding: 16px 14px 6px; }
  .composer { padding: 11px 14px 14px; }
  .offline-banner { display: none; }
}
