:root {
  --canvas: #e9e8e4;
  --card: #fbfaf8;
  --bg-side: #e2e1dc;
  --bg-input: #f0efeb;
  --text: #2a2a2a;
  --text-dim: #8a887f;
  --accent: #3b82f6;
  --danger: #dc2626;
  --border: #d8d6cf;
  --bubble-user: #dbeafe;
  --bubble-user-text: #1e3a5f;
  --bubble-ai: #ffffff;
  --bubble-ai-text: #2a2a2a;
  --paper-border: #e8e6df;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--canvas);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
  padding: 12px;
  gap: 12px;
}

/* ── 左栏(会话标签框, 圆角卡片) ── */
#sidebar {
  width: 280px;
  min-width: 200px;
  background: var(--bg-side);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 0 16px;
  height: 48px;
  display: flex;
  align-items: center;
  font-size: 15px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

#agent-list {
  flex: 1;
  overflow-y: auto;
}

.agent-group {
  border-bottom: 1px solid var(--border);
}

.agent-toggle {
  width: 100%;
  padding: 12px 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}

.agent-toggle:hover { background: rgba(0,0,0,0.04); }

.agent-toggle .arrow { font-size: 11px; color: #6b6962; width: 12px; display: inline-block; }

.agent-badge {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: auto;
  background: #d2d0c9;
  padding: 2px 8px;
  border-radius: 10px;
}

.session-list { list-style: none; }

.session-item {
  padding: 8px 16px 8px 36px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item:hover { background: rgba(0,0,0,0.04); color: var(--text); }
.session-item.active { background: rgba(59,130,246,0.1); color: var(--accent); }
.session-item.archived { opacity: 0.5; }

/* ── 右栏 ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

/* 聊天记录框(圆角卡片) */
#chat-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
}

#chat-header {
  padding: 0 16px;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

#current-agent { font-weight: 600; }
#current-session { color: var(--text-dim); font-size: 12px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#header-actions { display: flex; gap: 4px; }

/* 图标按钮统一样式 */
.icon-btn {
  background: transparent;
  border: none;
  color: #4a4842;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 8px;
  padding: 8px;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:hover { background: #e0ded8; color: #1a1a1a; }

/* ── 消息区(纸张纹理) ── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background:
    repeating-linear-gradient(0deg, rgba(120,110,90,0.015) 0px, rgba(120,110,90,0.015) 1px, transparent 1px, transparent 3px),
    var(--card);
}

.msg { max-width: 75%; padding: 12px 16px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 1.6; }
.msg.user { align-self: flex-end; background: var(--bubble-user); color: var(--bubble-user-text); }
.msg.ai { align-self: flex-start; background: var(--bubble-ai); color: var(--bubble-ai-text); border: 1px solid var(--paper-border); box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.msg img { max-width: 100%; border-radius: 8px; margin: 6px 0; }

.msg .role-tag { font-size: 11px; opacity: 0.55; display: block; margin-bottom: 4px; }

/* ── 输入框(圆角卡片) ── */
#composer {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  background: var(--card);
}

#attachments {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.attach-item {
  position: relative;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.attach-item img { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; }
.attach-item .rm { cursor: pointer; color: var(--danger); }

#input-row { display: flex; align-items: center; gap: 8px; }

#input {
  flex: 1;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  resize: none;
  font-family: inherit;
  line-height: 1.5;
  min-height: 66px;
  overflow-y: auto;
}
#input:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0 18px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  height: 42px;
  flex-shrink: 0;
  margin-left: 8px;
}
.send-btn:hover { opacity: 0.9; }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── 拖拽高亮 ── */
#composer.dragging {
  border: 1px solid var(--accent);
  background: rgba(59,130,246,0.05);
}

/* ── 响应式(手机) ── */
@media (max-width: 768px) {
  #sidebar { position: absolute; left: 12px; top: 12px; bottom: 12px; z-index: 100; transform: translateX(-120%); transition: transform 0.25s; width: 260px; }
  #sidebar.open { transform: translateX(0); }
  .msg { max-width: 90%; }
  #input { min-height: 30px; }
}
