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

:root {
  --bg: #0d1017;
  --panel: #151a24;
  --panel2: #1b2130;
  --border: #28304a;
  --text: #e6e9ef;
  --muted: #8b93a5;
  --accent: #34d399;
  --user: #3b82f6;
  --assistant: #a78bfa;
  --system: #64748b;
  --danger: #f87171;
  --warn: #f59e0b;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.65 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden { display: none !important; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #2c344a; border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 顶栏 ---------- */

header {
  height: 54px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.brand .sub { color: var(--muted); font-weight: 400; font-size: 12px; }

.logo {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.header-right { display: flex; align-items: center; gap: 16px; }
.header-count { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }

.badge {
  background: var(--danger); color: #fff;
  border-radius: 10px; padding: 0 8px;
  font-size: 12px; font-weight: 700; line-height: 20px;
}
.badge.zero { background: #3a4358; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--accent); }
.dot.off { background: var(--danger); }
.conn { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }

/* ---------- 布局 ---------- */

main { flex: 1; display: grid; grid-template-columns: 330px 1fr; min-height: 0; }

aside {
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#detailPane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

/* ---------- 队列 / 历史 ---------- */

.tabs { display: flex; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.tabs button {
  flex: 1; background: none; border: none;
  color: var(--muted); padding: 11px 8px;
  cursor: pointer; font-size: 13px; font-family: inherit;
}
.tabs button.active { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.tab-count { color: var(--danger); font-weight: 700; }

.list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.list-empty { color: var(--muted); text-align: center; padding: 36px 0; font-size: 13px; }

.card {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color .12s;
}
.card:hover { border-color: #3b4664; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card-key { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chip {
  font-size: 11px; color: var(--muted);
  border: 1px solid var(--border);
  padding: 1px 8px; border-radius: 999px;
  white-space: nowrap; flex: 0 0 auto;
}

.card-preview {
  color: var(--text); opacity: .85;
  margin: 6px 0; font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.card-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.card-meta .model { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wait { color: var(--warn); }
.status.answered { color: var(--accent); }
.status.timeout { color: var(--danger); }
.status.rejected { color: var(--warn); }
.status.aborted { color: var(--muted); }
.time { color: var(--muted); }

/* ---------- 详情 ---------- */

.detail-meta {
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; gap: 12px; align-items: center;
  color: var(--muted); font-size: 13px;
  flex-wrap: wrap; flex: 0 0 auto;
}
.detail-meta .meta-key { color: var(--text); font-weight: 600; }

#detailView { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.messages {
  flex: 1; overflow-y: auto;
  padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
}

.bubble {
  max-width: 80%;
  border-radius: 12px;
  padding: 8px 12px;
  background: var(--panel2);
  border: 1px solid var(--border);
}
.bubble .role { font-size: 11px; color: var(--muted); }
.bubble-body { white-space: pre-wrap; word-break: break-word; margin-top: 2px; font-size: 13.5px; }

.bubble.user { align-self: flex-start; border-left: 3px solid var(--user); }
.bubble.assistant { align-self: flex-start; border-left: 3px solid var(--assistant); }
.bubble.tool { align-self: flex-start; border-left: 3px solid var(--warn); }
.bubble.system { align-self: center; background: transparent; border-style: dashed; max-width: 92%; }
.bubble.latest { border-color: var(--user); box-shadow: 0 0 0 1px var(--user); }

details.folded summary { cursor: pointer; color: var(--muted); font-size: 12px; user-select: none; }
details.folded[open] summary { margin-bottom: 6px; }
details.folded .bubble-body { margin-top: 0; }

/* ---------- 输入区 ---------- */

.composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  padding: 12px 18px;
  background: var(--panel);
  display: flex; flex-direction: column; gap: 10px;
}

textarea {
  width: 100%; min-height: 96px; max-height: 40vh;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font: inherit; line-height: 1.6;
  resize: vertical;
}
textarea:focus { outline: none; border-color: var(--accent); }

.composer-actions { display: flex; align-items: center; gap: 12px; }
.hint { color: var(--muted); font-size: 12px; margin-left: auto; }

button.primary {
  background: var(--accent); color: #052e1c;
  font-weight: 700; border: none;
  padding: 9px 18px; border-radius: 9px;
  cursor: pointer; font-size: 14px; font-family: inherit;
}
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: .5; cursor: default; }

button.ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 9px;
  cursor: pointer; font-size: 13px; font-family: inherit;
}
button.ghost:hover { color: var(--text); border-color: #3b4664; }
button.ghost.small { padding: 4px 10px; font-size: 12px; }

/* ---------- 历史结果 ---------- */

#historyResult { flex: 0 0 auto; border-top: 1px solid var(--border); padding: 14px 18px; background: var(--panel); }
.result-box { max-width: 80%; }
.result-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.result-text {
  background: var(--panel2); border: 1px solid var(--accent);
  border-radius: 12px; padding: 8px 12px;
  white-space: pre-wrap; word-break: break-word;
}

/* ---------- 空状态 ---------- */

.empty {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; color: var(--muted);
  padding: 30px; text-align: center;
}
.empty h3 { color: var(--text); font-size: 16px; }
.empty-icon { font-size: 40px; }

.empty-cfg {
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 20px;
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; text-align: left;
}
.empty code {
  background: var(--panel2); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 6px;
  color: var(--accent); font-size: 12.5px;
}

/* ---------- 口令弹层 ---------- */

.overlay {
  position: fixed; inset: 0;
  background: rgba(5, 8, 14, .82);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px;
  width: 350px;
  display: flex; flex-direction: column; gap: 12px;
}
.auth-card h2 { font-size: 17px; }
.auth-card p { color: var(--muted); font-size: 13px; }
.auth-card code { color: var(--accent); font-size: 12px; }
.auth-card input {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 10px 12px; font: inherit;
}
.auth-card input:focus { outline: none; border-color: var(--accent); }
.err { color: var(--danger); font-size: 13px; }

/* ---------- 小屏 ---------- */

@media (max-width: 860px) {
  main { grid-template-columns: 1fr; grid-template-rows: minmax(180px, 34vh) 1fr; }
  aside { border-right: none; border-bottom: 1px solid var(--border); }
  .bubble { max-width: 94%; }
  .brand .sub { display: none; }
}
