/* ============================================================
 * JL Bank 客服问答系统 — 阶段三原型样式
 * 视觉取向：HiAgent/豆包风格 + Arco token
 * 工程形态：原生零构建，贴合前端 SPEC §2.1
 * ============================================================ */

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: var(--fs-base);
  line-height: var(--lh);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

#app { width: 100%; height: 100%; }
.hidden { display: none !important; }

/* ============================================================
 * 1. 认证视图
 * ============================================================ */
.auth-view {
  width: 100%; min-height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 10% 20%, rgba(59,130,246,.08) 0%, transparent 28%),
    radial-gradient(circle at 90% 80%, rgba(31,59,102,.08) 0%, transparent 28%),
    var(--bg);
}

.auth-card {
  width: 100%; max-width: 420px;
  padding: 36px 32px 28px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  text-align: center;
}

.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 64px; height: 64px;
  margin-bottom: 18px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  border-radius: 16px;
  box-shadow: 0 6px 18px rgba(31,59,102,.22);
}
.brand-mark svg { width: 30px; height: 30px; stroke: #fff; }

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 24px; font-weight: 600;
  color: var(--text);
}

.auth-subtitle {
  margin: 0 0 28px;
  font-size: var(--fs-sm);
  color: var(--muted);
}

.auth-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 24px;
  background: var(--card-2);
  border-radius: var(--radius-pill);
}

.auth-tabs .tab {
  padding: 8px 20px;
  border: none; border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.auth-tabs .tab.active,
.auth-tabs .tab:hover {
  background: var(--card);
  color: var(--brand);
  box-shadow: var(--shadow);
}

.auth-form { text-align: left; }

.field {
  display: block; margin-bottom: 16px;
}

.field span {
  display: block; margin-bottom: 6px;
  font-size: var(--fs-sm); color: var(--text-2); font-weight: 500;
}

.field input {
  width: 100%;
  height: var(--hit);
  padding: 0 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--fs-base);
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}

.auth-error {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px; margin: -4px 0 16px;
  background: var(--danger-bg);
  border: 1px solid rgba(245,63,63,.25);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: var(--fs-sm);
}

.btn-primary {
  width: 100%; height: var(--hit);
  margin-top: 4px;
  background: linear-gradient(135deg, var(--brand-2), var(--accent));
  border: none; border-radius: var(--radius);
  color: #fff; font-size: var(--fs-base); font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(31,59,102,.22);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(31,59,102,.28); }
.btn-primary:active { transform: translateY(0); }

.auth-footer {
  margin-top: 20px;
  font-size: var(--fs-xs); color: var(--muted);
}

/* ============================================================
 * 2. 应用壳与侧栏
 * ============================================================ */
.app-shell {
  display: flex;
  width: 100%; height: 100%;
  overflow: hidden;
}

.sidebar {
  display: flex; flex-direction: column;
  width: 280px; min-width: 280px; height: 100%;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  transition: transform var(--dur) var(--ease);
}

.sidebar-header {
  padding: 18px 16px 12px;
}

.brand-mini {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px;
}

.brand-icon {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  color: #fff;
  border-radius: 10px;
}
.brand-icon svg { width: 20px; height: 20px; stroke: #fff; }

.brand-text { display: flex; flex-direction: column; gap: 1px; }
.brand-title { font-size: 15px; font-weight: 600; color: var(--text); }
.brand-tag { font-size: var(--fs-xs); color: var(--muted); }

.btn-new-chat {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; height: 40px;
  background: var(--card-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text); font-size: var(--fs-sm); font-weight: 500;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}

.btn-new-chat:hover {
  background: rgba(59,130,246,.08);
  border-color: var(--accent);
  color: var(--accent);
}

.sidebar-search {
  position: relative;
  margin: 0 16px 12px;
}

.sidebar-search input {
  width: 100%; height: 36px;
  padding: 0 12px 0 32px;
  background: var(--card-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text); font-size: var(--fs-sm);
  outline: none;
}

.sidebar-search input:focus { border-color: var(--accent); background: var(--card); }

.search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--muted);
}

.sidebar-section-title {
  padding: 8px 20px 6px;
  font-size: var(--fs-xs); color: var(--muted); font-weight: 500;
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 12px;
}

.conv-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}

.conv-item:hover { background: var(--gray-1); }
.conv-item.active { background: rgba(59,130,246,.10); }

.conv-icon {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; min-width: 28px;
  background: var(--card-2);
  border-radius: 8px;
  color: var(--muted);
}
.conv-icon svg { width: 15px; height: 15px; stroke: var(--muted); }

.conv-item.active .conv-icon {
  background: var(--accent); color: #fff;
}
.conv-item.active .conv-icon svg { stroke: #fff; }

.conv-info { flex: 1; min-width: 0; }
.conv-title {
  font-size: var(--fs-sm); color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-meta {
  display: flex; align-items: center; gap: 8px;
  margin-top: 2px;
  font-size: var(--fs-xs); color: var(--muted);
}

.conv-delete {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 6px;
  background: transparent; color: var(--muted);
  cursor: pointer; opacity: 0;
  transition: opacity var(--dur) var(--ease), background var(--dur) var(--ease);
}

.conv-item:hover .conv-delete { opacity: 1; }
.conv-delete:hover { background: var(--danger-bg); color: var(--danger); }
.conv-delete svg { width: 14px; height: 14px; stroke: currentColor; }

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

.worker-badge {
  display: flex; align-items: center; gap: 8px;
}

.avatar {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: var(--card-2);
  border-radius: var(--radius-pill);
  color: var(--text-2); font-size: 12px; font-weight: 600;
}

.worker-name { font-size: var(--fs-sm); color: var(--text); font-weight: 500; }

.sidebar-actions { display: flex; gap: 6px; }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: var(--fs-sm);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}

.btn-icon:hover { background: var(--card-2); color: var(--text); }

.sidebar-footer .avatar {
  background: var(--card-2);
  color: var(--text-2);
}
.sidebar-footer .avatar svg { width: 18px; height: 18px; stroke: var(--text-2); }

/* ============================================================
 * 3. 主聊天区
 * ============================================================ */
.chat {
  flex: 1;
  display: flex; flex-direction: column;
  min-width: 0;
  background: var(--bg);
  position: relative;
}

.chat-header {
  display: flex; align-items: center; gap: 12px;
  height: 60px;
  padding: 0 20px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.btn-toggle-sidebar {
  display: none;
  width: 34px; height: 34px;
  background: transparent; border: none;
  color: var(--text-2); font-size: 18px;
  cursor: pointer; border-radius: var(--radius-sm);
}

.btn-toggle-sidebar:hover { background: var(--card-2); }

.chat-title-wrap { flex: 1; min-width: 0; }
.chat-title { margin: 0; font-size: var(--fs-md); font-weight: 600; color: var(--text); }
.chat-meta { font-size: var(--fs-xs); color: var(--muted); margin-left: 8px; }

.chat-actions { display: flex; gap: 6px; }

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 12px;
  scroll-behavior: smooth;
}

/* 空态 */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100%;
  padding-bottom: 120px;
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 20px;
  font-size: 28px; font-weight: 600;
  color: var(--text);
}

.mode-toggle {
  display: inline-flex; gap: 4px;
  padding: 4px;
  margin-bottom: 28px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

.mode-toggle button {
  padding: 7px 20px;
  background: transparent; border: none; border-radius: var(--radius-pill);
  color: var(--muted); font-size: var(--fs-sm);
  cursor: pointer;
}

.mode-toggle button.active {
  background: var(--card-2);
  color: var(--text); font-weight: 500;
}

.recommend-title {
  margin: 0 0 12px;
  font-size: var(--fs-xs); color: var(--muted);
}

.recommend-chips {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 10px; max-width: 640px;
}

.chip {
  padding: 10px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-2); font-size: var(--fs-sm);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--shadow);
}

/* 消息容器 */
.messages {
  max-width: 860px;
  margin: 0 auto;
}

.message {
  display: flex; gap: 12px;
  margin-bottom: 24px;
}

.message.user { flex-direction: row-reverse; }

.avatar-ai, .avatar-user {
  width: 36px; height: 36px; min-width: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.avatar-ai {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--brand);
}

.avatar-ai svg { width: 20px; height: 20px; stroke: var(--brand); }

.avatar-user {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
}

.avatar-user svg { width: 20px; height: 20px; stroke: var(--user-bubble-text); }

.bubble-wrap { max-width: 88%; display: flex; flex-direction: column; }

.message.user .bubble-wrap { align-items: flex-end; }
.message.assistant .bubble-wrap { align-items: flex-start; }

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: var(--fs-base);
  line-height: 1.7;
  word-break: break-word;
  white-space: pre-wrap;
}

.bubble.user {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
}

.bubble.assistant {
  background: var(--assistant-bubble);
  color: var(--assistant-bubble-text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}

/* 内联引用角标（对应助手回答中的 ① ② ③） */
.cite-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px; height: 18px;
  margin: 0 1px;
  padding: 0 4px;
  background: var(--cite-bg);
  border: 1px solid var(--cite-border);
  border-radius: 4px;
  color: var(--cite-text);
  font-size: 11px; font-weight: 600;
  vertical-align: middle;
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}

.cite-inline:hover { background: rgba(59,130,246,.18); }

/* 消息元信息 */
.msg-meta {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 6px;
}

.msg-time { font-size: var(--fs-xs); color: var(--muted); }

.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: 500;
}

.badge-intent {
  background: rgba(59,130,246,.10);
  color: var(--accent);
}

.badge-cached {
  background: rgba(0,180,42,.10);
  color: var(--success);
}

.badge-reject {
  background: rgba(255,125,0,.10);
  color: var(--warning);
}

/* 改写横幅 */
.rewrite-banner {
  display: inline-flex; align-items: center; gap: 6px;
  margin-bottom: 10px;
  padding: 6px 10px;
  background: var(--gray-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2); font-size: var(--fs-sm);
}

.rewrite-banner strong { color: var(--text); font-weight: 500; }

/* Agent 调用逻辑轨迹条 —— 作为回答气泡内部的顶部小横条（与气泡同宽），默认折叠、一键展开 */
.agent-trace {
  display: flex; flex-direction: column; gap: 6px;
  margin: 0 0 12px;
  padding: 0 0 10px;
  font-size: var(--fs-xs);
  color: var(--assistant-bubble-text);
  border-bottom: 1px dashed var(--border);
  transition: border-color var(--dur) var(--ease);
}
.agent-trace.complete { border-bottom-color: transparent; }

/* 头部可整行点击展开/收起 */
.at-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  cursor: pointer;
  user-select: none;
}
.at-head-left {
  display: inline-flex; align-items: center; gap: 6px;
  min-width: 0;
}
.at-title {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--muted); font-weight: 600; letter-spacing: .2px; flex-shrink: 0;
}
.at-bolt { color: var(--accent); }

/* 折叠箭头钮（展开态可见：用于收起） */
.at-toggle {
  display: none; align-items: center; justify-content: center;
  width: 20px; height: 20px; flex: 0 0 20px;
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--muted); cursor: pointer; padding: 0;
  transition: all .15s var(--ease);
}
.at-toggle:hover { background: var(--card-2); color: var(--accent); }
.agent-trace:not(.collapsed) .at-toggle { display: inline-flex; }
.at-caret { transition: transform .22s var(--ease); }

.at-summary {
  color: var(--muted); text-align: right;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 步骤主体：grid-rows 0fr<->1fr 平滑折叠 */
.at-collapse {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows .28s var(--ease), opacity .22s var(--ease);
}
.agent-trace.collapsed .at-collapse {
  grid-template-rows: 0fr;
  opacity: 0;
}

.at-collapse-inner {
  overflow: hidden; min-height: 0;
  display: flex; flex-wrap: wrap; align-items: center; column-gap: 4px; row-gap: 4px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}
.at-node { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.at-dot {
  width: 15px; height: 15px; border-radius: 50%;
  flex: 0 0 15px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; line-height: 1;
  color: #fff;
  transition: background var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.at-name { color: var(--text-2); font-weight: 500; white-space: nowrap; }
.at-ms { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.at-note { color: var(--muted); white-space: nowrap; }
.at-arrow { color: var(--gray-4); padding: 0 3px; }

.at-node.pending .at-dot { background: var(--gray-4); }
.at-node.running .at-dot {
  background: var(--accent);
  animation: stagePulse 1s infinite ease-in-out both;
}
.at-node.running .at-name { color: var(--accent); }
.at-node.done .at-dot { background: var(--success); }
.at-node.idle { opacity: .55; }

@media (prefers-reduced-motion: reduce) {
  .at-node.running .at-dot { animation: none; }
}

/* 阶段指示器（已由 Agent 轨迹条取代，保留兼容但不使用） */
.stage-indicator {
  display: inline-flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
  padding: 7px 12px;
  background: var(--gray-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--fs-sm); color: var(--text-2);
}

.stage-dots {
  display: flex; gap: 4px;
}

.stage-dots span {
  width: 6px; height: 6px;
  background: var(--gray-4);
  border-radius: 50%;
  animation: stagePulse 1.2s infinite ease-in-out both;
}

.stage-dots span:nth-child(1) { animation-delay: 0s; }
.stage-dots span:nth-child(2) { animation-delay: .15s; }
.stage-dots span:nth-child(3) { animation-delay: .3s; }

@keyframes stagePulse {
  0%, 80%, 100% { transform: scale(.7); opacity: .5; }
  40% { transform: scale(1); opacity: 1; background: var(--accent); }
}

@media (prefers-reduced-motion: reduce) {
  .stage-dots span { animation: none; opacity: 1; background: var(--accent); }
}

/* 引用底栏 */
.citation-bar {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--divider);
}

.cite-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  background: var(--cite-bg);
  border: 1px solid var(--cite-border);
  border-radius: var(--radius-sm);
  color: var(--cite-text);
  font-size: var(--fs-xs);
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}

.cite-chip:hover { background: rgba(59,130,246,.16); }

.cite-chip .idx {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px;
  background: var(--accent); color: #fff;
  border-radius: 4px; font-size: 11px; font-weight: 600;
}

/* 消息操作 */
.msg-actions {
  display: flex; gap: 6px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}

.message:hover .msg-actions { opacity: 1; }

.msg-actions button {
  padding: 4px 8px;
  background: transparent;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--muted); font-size: var(--fs-xs);
  cursor: pointer;
}

.msg-actions button:hover { background: var(--card-2); color: var(--text); }

/* 输入区 */
.chat-input-area {
  padding: 12px 20px 18px;
  background: var(--bg);
}

.round-hint {
  display: flex; align-items: center; gap: 6px;
  max-width: 860px; margin: 0 auto 10px;
  padding: 8px 12px;
  background: rgba(255,125,0,.08);
  border: 1px solid rgba(255,125,0,.25);
  border-radius: var(--radius);
  color: var(--warning); font-size: var(--fs-sm);
}

.input-box {
  display: flex; align-items: flex-end; gap: 10px;
  max-width: 860px; margin: 0 auto;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.input-box:focus-within { border-color: var(--accent); }

.btn-upload, .btn-send {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; min-width: 36px;
  border: none; border-radius: var(--radius-pill);
  cursor: pointer;
}

.btn-upload {
  background: transparent;
  color: var(--muted);
}

.btn-upload:hover { background: var(--gray-1); color: var(--text); }

.btn-send {
  background: var(--accent);
  color: #fff;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.btn-send:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-send:disabled { background: var(--gray-4); cursor: not-allowed; transform: none; }

#chat-input {
  flex: 1;
  max-height: 160px; min-height: 24px;
  padding: 8px 4px;
  background: transparent;
  border: none; outline: none; resize: none;
  color: var(--text); font-size: var(--fs-base); line-height: 1.5;
  font-family: inherit;
}

#chat-input::placeholder { color: var(--muted); }

.disclaimer {
  max-width: 860px; margin: 8px auto 0;
  text-align: center;
  font-size: var(--fs-xs); color: var(--muted);
}

/* ============================================================
 * 4. 右侧「卡片空间」抽屉
 * ============================================================ */
.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 95;
  opacity: 1;
  transition: opacity .22s var(--ease);
}
.drawer-backdrop.hidden { opacity: 0; pointer-events: none; }

.drawer {
  position: fixed; top: 0; right: 0;
  width: 420px; max-width: 90vw; height: 100%;
  background: var(--card);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-drawer);
  z-index: 100;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .28s var(--ease);
}

.drawer:not(.hidden) { transform: translateX(0); }
.drawer.drawer-leave { transform: translateX(100%); }

.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px; padding: 0 20px;
  border-bottom: 1px solid var(--border);
}

.drawer-header h3 {
  display: flex; align-items: center; gap: 8px;
  margin: 0; font-size: var(--fs-md); font-weight: 600; color: var(--text);
}

.btn-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: var(--radius-sm);
  color: var(--muted); font-size: 22px; line-height: 1;
  cursor: pointer;
  transition: transform .22s var(--ease), background .22s var(--ease), color .22s var(--ease);
}

.btn-close:hover { background: var(--card-2); color: var(--text); transform: rotate(90deg); }

.drawer-tabs {
  display: flex; gap: 24px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
}

.drawer-tabs .tab {
  position: relative;
  padding: 14px 0;
  background: transparent; border: none;
  color: var(--muted); font-size: var(--fs-base);
  cursor: pointer;
  transition: color .22s var(--ease);
}

.drawer-tabs .tab.active { color: var(--text); font-weight: 500; }

.drawer-tabs .tab::after {
  content: '';
  position: absolute; bottom: 0; left: 0; right: 0;
  height: 2px; background: var(--accent); border-radius: 2px 2px 0 0;
  transform: scaleX(0);
  transition: transform .22s var(--ease);
}
.drawer-tabs .tab.active::after { transform: scaleX(1); }

.drawer-body {
  flex: 1; overflow-y: auto;
  padding: 16px 20px;
}

@keyframes cardSlideIn {
  from { opacity: 0; transform: translateY(16px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.source-card-enter {
  animation: cardSlideIn .35s var(--ease) both;
}

.source-card {
  padding: 10px 14px;
  margin-bottom: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: transform .22s var(--ease), box-shadow .22s var(--ease), border-color .22s var(--ease);
  cursor: pointer;
}

.source-card:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--accent);
}

.source-card.collapsed .source-title .name { color: var(--text-2); }

.source-head {
  display: flex; align-items: center; gap: 8px;
}

/* 折叠/展开 平滑过渡：content 用 grid-rows 0fr<->1fr */
.source-collapse {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows .28s var(--ease), opacity .22s var(--ease), margin .28s var(--ease);
}
.source-collapse-inner { overflow: hidden; min-height: 0; }

.source-card.collapsed .source-collapse {
  grid-template-rows: 0fr;
  opacity: 0;
  margin: 0;
}

/* toggle 左箭头钮（仅展开态可见，用于收起） */
.sc-toggle {
  display: none; align-items: center; justify-content: center;
  width: 22px; height: 22px; flex: 0 0 22px;
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--muted); cursor: pointer; padding: 0;
  transition: all .15s var(--ease);
}
.sc-toggle:hover { background: var(--gray-1); color: var(--text); }
.source-card:not(.collapsed) .sc-toggle { display: inline-flex; }

.source-title {
  display: flex; align-items: center; gap: 8px;
  flex: 1; min-width: 0;
}

.source-title .num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; flex: 0 0 22px;
  background: var(--accent); color: #fff;
  border-radius: 6px; font-size: 12px; font-weight: 700;
}

.source-title .name {
  color: var(--text); font-size: var(--fs-base); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.source-head-right {
  display: flex; align-items: center; gap: 8px;
  flex: 0 0 auto;
}

.source-actions { display: flex; gap: 8px; margin-top: 10px; }

.source-actions button {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 10px;
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--muted); font-size: var(--fs-xs);
  cursor: pointer;
  transition: all .15s var(--ease);
}

.source-actions button:hover { background: var(--card-2); color: var(--text); }

.source-path {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
  margin: 8px 0 8px 0;
  color: var(--muted); font-size: var(--fs-xs); line-height: 1.6;
  word-break: break-all;
}

.source-path strong { color: var(--text-2); font-weight: 500; }

.source-score {
  padding: 2px 8px;
  background: rgba(59,130,246,.08);
  border-radius: var(--radius-pill);
  color: var(--accent); font-size: var(--fs-xs); font-weight: 500;
  flex: 0 0 auto;
}

.source-snippet {
  padding: 10px 12px;
  background: var(--gray-1);
  border-radius: var(--radius-sm);
  color: var(--text-2); font-size: var(--fs-sm); line-height: 1.7;
}

.source-snippet mark {
  background: var(--mark-bg); color: var(--mark-text);
  padding: 1px 2px; border-radius: 2px;
}

/* 展开/收起主按钮 */
.btn-expand {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 3px 8px;
  background: var(--gray-1); border: 1px solid var(--border); border-radius: var(--radius-pill);
  color: var(--text-2); font-size: var(--fs-xs); cursor: pointer;
  transition: all .15s var(--ease);
  white-space: nowrap;
}
.btn-expand:hover { background: var(--card-2); color: var(--accent); }
.sc-chev { flex: 0 0 auto; transition: transform .22s var(--ease); }

/* ============================================================
 * 5. 回答来源弹窗
 * ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.45);
  z-index: 200;
  opacity: 1;
  transition: opacity var(--dur) var(--ease);
}

.modal-backdrop.hidden { opacity: 0; pointer-events: none; }

.modal {
  width: 640px; max-width: 90vw; max-height: 80vh;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  display: flex; align-items: center; gap: 8px;
  margin: 0; font-size: var(--fs-md); font-weight: 600;
}

.modal-body {
  flex: 1; overflow-y: auto;
  padding: 0;
}

/* --- 分栏来源弹窗 --- */
.modal.source-modal { width: 900px; max-width: 94vw; }

.modal-doc-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.modal-doc-title {
  display: flex; align-items: center; gap: 10px;
}

.modal-doc-title .doc-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(245,63,63,.08);
  border-radius: 8px;
  color: var(--danger);
  flex-shrink: 0;
}

.modal-doc-title .doc-name {
  color: var(--text); font-weight: 500;
  cursor: pointer;
}
.modal-doc-title .doc-name:hover { color: var(--accent); }

.modal-doc-title .icon-link {
  color: var(--muted);
  cursor: pointer;
  transition: color .15s var(--ease);
  flex-shrink: 0;
}
.modal-doc-title .icon-link:hover { color: var(--accent); }

.modal-doc-meta {
  display: flex; align-items: center; gap: 12px;
}

.hit-count {
  font-size: var(--fs-sm); color: var(--text-2);
}

.modal-split {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, .95fr);
  align-items: stretch;
  gap: 0;
  padding: 14px 18px 18px;
  /* 让左右两栏在自身区域内滚动，形成真正独立双栏 */
  max-height: calc(80vh - 116px);
  overflow: hidden;
}

.modal-split-col {
  min-height: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* 右栏与左栏之间用一条竖向分隔线区分“双栏位” */
.modal-split-right {
  border-left: 1px solid var(--border);
  padding-left: 16px;
}

.col-header {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px;
  padding: 2px 2px 10px;
  flex-shrink: 0;
}

.col-header .col-title {
  font-size: var(--fs-sm); font-weight: 700; color: var(--text);
  letter-spacing: .02em;
}

.col-header .col-title::before {
  content: '';
  display: inline-block;
  width: 3px; height: 12px;
  margin-right: 7px;
  border-radius: 2px;
  background: var(--accent);
  vertical-align: -1px;
}

.col-header .col-sub {
  font-size: var(--fs-xs); color: var(--muted);
}

/* 左栏：原文预览（内部滚动） */
.modal-split-left {
  padding-right: 16px;
}

.modal-doc-preview {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  font-size: var(--fs-sm); line-height: 1.85;
  color: var(--text-2);
}

.modal-doc-path {
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--divider);
  font-size: var(--fs-sm);
  color: var(--text);
}

.modal-doc-path .path-node {
  display: inline-flex; align-items: center;
  color: var(--text); font-weight: 500;
}

.modal-doc-path .path-node:first-child { color: var(--accent); }

.modal-doc-path .path-arrow {
  color: var(--muted);
  font-size: 12px;
}

.preview-body {
  white-space: normal;
}

.preview-body mark {
  background: var(--mark-bg); color: var(--mark-text);
  padding: 1px 2px; border-radius: 2px;
}

/* 右栏：命中信息列表 */
.modal-hit-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
  padding: 0 2px 2px 0;
}

.hit-item {
  padding: 13px 14px;
  background: var(--gray-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background .15s var(--ease), box-shadow .15s var(--ease);
}

.hit-item:hover {
  background: var(--card-2);
  box-shadow: var(--shadow-sm);
}

.hit-item-head {
  display: flex; align-items: flex-start; gap: 8px;
  margin-bottom: 10px;
}

.hit-badge {
  flex-shrink: 0;
  padding: 2px 8px;
  background: rgba(59,130,246,.1);
  border-radius: var(--radius-pill);
  color: var(--accent);
  font-size: var(--fs-xs); font-weight: 600;
}

.hit-question {
  flex: 1;
  font-size: var(--fs-sm); font-weight: 600; color: var(--text);
  line-height: 1.5;
}

.hit-fields {
  display: flex; flex-direction: column; gap: 7px;
  margin: 0 0 10px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--divider);
}

.hit-fields .hf {
  display: flex; align-items: baseline; gap: 10px;
  font-size: var(--fs-xs);
}

.hit-fields dt {
  flex-shrink: 0;
  width: 52px;
  color: var(--muted);
}

.hit-fields dd {
  margin: 0; color: var(--text-2);
  word-break: break-all;
}

.hit-fields dd code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--text);
  background: var(--card-2);
  padding: 1px 5px;
  border-radius: 4px;
}

.hit-fields .score-val {
  color: var(--accent);
  font-weight: 700;
}

.hit-snippet {
  font-size: var(--fs-xs); line-height: 1.7;
  color: var(--text-2);
}

.hit-snippet mark {
  background: var(--mark-bg); color: var(--mark-text);
  padding: 1px 2px; border-radius: 2px;
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(.96) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-enter {
  animation: modalPop .25s var(--ease) both;
}

/* ============================================================
 * 6. 轻提示
 * ============================================================ */
.toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: var(--text); color: #fff;
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-pop);
  z-index: 300;
  opacity: 1;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(12px); }

/* ============================================================
 * 7. 统一图标系统（SVG icon）
 * ============================================================ */
.icon {
  display: inline-block;
  width: 1em; height: 1em;
  stroke-width: 2;
  stroke: currentColor;
  fill: none;
  vertical-align: middle;
  flex-shrink: 0;
}

.source-actions button,
.msg-actions button,
.btn-view-source,
.btn-download { display: inline-flex; align-items: center; gap: 4px; }

.source-actions button svg,
.btn-view-source svg,
.btn-download svg { width: 14px; height: 14px; stroke: currentColor; }

/* ============================================================
 * 8. 微动效增强
 * ============================================================ */
.cite-inline {
  transition: transform .15s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease);
}
.cite-inline:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(59,130,246,.18);
}

.cite-chip {
  transition: transform .15s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease);
}
.cite-chip:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(59,130,246,.12);
}

@keyframes messageEnter {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message {
  animation: messageEnter .28s var(--ease) both;
}

/* ============================================================
 * 9. 工具类与响应式
 * ============================================================ */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    z-index: 90;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .btn-toggle-sidebar { display: flex; align-items: center; justify-content: center; }
  .bubble-wrap { max-width: 92%; }
}

@media (max-width: 840px) {
  /* 窄屏：由左右双栏降级为上下堆叠，保证可读性 */
  .modal-split {
    grid-template-columns: 1fr;
    max-height: none;
    overflow-y: auto;
  }
  .modal-split-left { padding-right: 0; }
  .modal-split-right {
    border-left: none;
    border-top: 1px solid var(--border);
    padding-left: 0;
    padding-top: 14px;
    margin-top: 4px;
  }
  .modal-doc-preview,
  .modal-hit-list { overflow-y: visible; }
  .modal.source-modal { width: 96vw; max-height: 88vh; }
}

@media (max-width: 640px) {
  .auth-card { padding: 28px 22px; }
  .chat-header { padding: 0 12px; }
  .chat-body { padding: 16px 12px 8px; }
  .chat-input-area { padding: 10px 12px 14px; }
  .drawer { width: 100vw; max-width: 100vw; }
  .modal-doc-header { flex-direction: column; align-items: flex-start; }
}
