/* ===== Chat View ===== */
.chat-header {
  position: sticky; top: 0; z-index: 10;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--slate-50);
}
.chat-header-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

.icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none;
  border-radius: var(--radius-full);
  color: var(--slate-600);
  cursor: pointer;
  font-size: 20px;
  transition: background 0.2s;
}
.icon-btn:hover { background: var(--slate-100); }

.chat-agent-info { text-align: center; }
.chat-agent-name { font-size: 14px; font-weight: 700; color: var(--slate-800); display: flex; align-items: center; gap: 6px; }
.chat-agent-status {
  display: inline-block;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--slate-300);
}

.agent-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; cursor: grab; }
.agent-tab {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  font-size: 12px; font-weight: 500; font-family: inherit;
  background: var(--white); border: 1px solid var(--slate-200);
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  color: var(--slate-600);
}
.agent-tab:hover { border-color: var(--slate-300); }
.agent-tab.active { color: var(--white); border-color: transparent; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.agent-tab i { font-size: 14px; }

.chat-messages {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 16px 16px 16px;
  display: flex; flex-direction: column; gap: 20px;
  background: rgba(248,250,252,0.3);
}

.empty-chat {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--slate-300); gap: 8px;
}
.empty-chat i { font-size: 40px; }
.empty-chat p { font-size: 14px; }

/* Chat messages */
.msg {
  display: flex; gap: 10px;
  width: fit-content;
  max-width: 88%;
  min-width: 0;
  animation: msgIn 0.3s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.bot {
  align-self: flex-start;
  width: 88%;
  max-width: 88%;
}
.msg.user {
  max-width: 82%;
}
.msg.system { align-self: center; width: 100%; display: flex; justify-content: center; animation: none; }
.system-bubble {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 13px;
  color: #fff;
  background: var(--primary);
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(79,70,229,0.2);
  text-align: left; max-width: 85%; line-height: 1.5;
}
.system-bubble i { margin-top: 2px; flex-shrink: 0; font-size: 16px; }
.sb-text { flex: 1; display: flex; flex-direction: column; }
.sb-title { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-desc { font-size: 12px; font-weight: 400; opacity: 0.85; margin-top: 4px; line-height: 1.5; }

.msg-avatar {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--white);
  font-size: 14px;
  position: relative;
  transition: all 0.2s ease;
}
.msg.bot .msg-avatar {
  background: var(--primary);
  box-shadow:
    0 0 0 2px var(--white),
    0 2px 8px rgba(139, 92, 246, 0.3),
    0 0 0 4px rgba(139, 92, 246, 0.1);
}
.msg.user .msg-avatar {
  background: var(--slate-100);
  color: var(--slate-500);
  box-shadow: 0 0 0 2px var(--white), 0 1px 4px rgba(0, 0, 0, 0.06);
}

.msg-body {
  display: flex; flex-direction: column; gap: 4px;
  min-width: 0;
  max-width: 100%;
}
.msg-bubble {
  max-width: 100%;
  padding: 12px 16px;
  font-size: 14px; line-height: 1.6;
  border-radius: var(--radius-lg);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  transition: box-shadow 0.15s ease;
}
.msg.user .msg-bubble {
  background: var(--primary);
  color: var(--white);
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.2);
}
.msg.bot .msg-bubble {
  background: var(--white);
  color: var(--slate-800);
  border: 1px solid var(--slate-100);
  border-bottom-left-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 0 0 1px rgba(139, 92, 246, 0.05);
}

/* 代码块 */
.code-block {
  margin: 8px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #1e293b;
  border: 1px solid #334155;
}
.code-block-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 12px;
  background: #0f172a;
  font-size: 12px; color: #94a3b8;
  border-bottom: 1px solid #334155;
}
.code-lang {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  text-transform: lowercase;
  letter-spacing: 0.5px;
}
.code-content {
  margin: 0;
  padding: 12px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #e2e8f0;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.code-line {
  min-height: 1.2em;
}

/* 表格 */
.table-wrapper {
  margin: 8px 0;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--slate-200);
}
.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.md-table th, .md-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--slate-100);
}
.md-table th {
  background: var(--slate-50);
  font-weight: 600;
  color: var(--slate-700);
}
.md-table tr:last-child td { border-bottom: none; }
.md-table tr:hover td { background: var(--slate-50); }

/* 列表项 */
.md-list-item {
  padding-left: 16px;
  position: relative;
  margin: 4px 0;
}
.md-list-item::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--primary);
  font-weight: bold;
}
.msg-time { font-size: 10px; color: var(--slate-300); }
.msg.user .msg-time { text-align: right; }

.cursor-blink {
  display: inline-block;
  width: 6px; height: 16px;
  background: var(--primary);
  animation: blink 0.7s infinite;
  vertical-align: middle;
  margin-left: 2px;
  border-radius: 1px;
}
@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0.2; }
}

/* 流式气泡渐入——msgIn 动画已由 .msg 提供，但流式更新时给气泡加呼吸感 */
.msg.bot .msg-bubble {
  transition: background-color 0.15s ease;
}
.msg.bot .msg-bubble:has(.cursor-blink) {
  background: linear-gradient(180deg, var(--white) 0%, rgba(245, 243, 255, 0.3) 100%);
}

.stream-placeholder-text {
  opacity: 0.88;
}

.stream-thinking-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  margin-left: 8px;
  vertical-align: middle;
}

.stream-thinking-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.25;
  animation: streamThinkingPulse 1.2s infinite ease-in-out;
}

.stream-thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.stream-thinking-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes streamThinkingPulse {
  0%,80%,100% { transform: translateY(0); opacity: 0.25; }
  40% { transform: translateY(-2px); opacity: 0.9; }
}

/* 打字指示器——精致化 */
.typing-indicator {
  display: flex; align-items: center; gap: 10px;
  opacity: 0;
  animation: typingFadeIn 0.3s ease forwards;
}
@keyframes typingFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 0.75; transform: translateY(0); }
}
.typing-dots { display: flex; gap: 5px; align-items: center; }
.typing-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--primary);
  animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.18s; }
.typing-dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes typingBounce {
  0%,80%,100% { transform: scale(0.6) translateY(0); opacity: 0.4; }
  40% { transform: scale(1) translateY(-4px); opacity: 1; }
  60% { transform: scale(0.85) translateY(1px); opacity: 0.8; }
}

/* Waiting Bubble */
.waiting-bubble {
  padding: 16px 18px;
  min-width: 240px;
}
.waiting-bubble .wb-step {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 500; color: var(--slate-800);
  animation: wb-fade-in 0.35s ease;
}
.waiting-bubble .wb-step i { font-size: 18px; color: var(--primary); }
@keyframes wb-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.waiting-bubble .wb-tip {
  font-size: 12px; color: var(--slate-400);
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--slate-100);
  animation: wb-fade-in 0.3s ease 0.15s both;
}
.waiting-bubble .wb-dots {
  display: flex; gap: 5px; margin-top: 10px;
  align-items: center;
}
.waiting-bubble .wb-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--slate-300);
  animation: wb-dot-pulse 1.4s infinite;
}
.waiting-bubble .wb-dot:nth-child(2) { animation-delay: 0.2s; }
.waiting-bubble .wb-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes wb-dot-pulse {
  0%,80%,100% { transform: scale(1); opacity: 0.4; }
  40% { transform: scale(1.2); opacity: 1; }
}

/* Input */
.chat-input-area {
  position: relative;
  padding: 12px 16px calc(24px + 72px);
  background: var(--white);
  border-top: 1px solid var(--slate-50);
}
.input-wrapper {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--slate-50);
  border-radius: var(--radius-xl);
  padding: 8px 8px 8px 12px;
  border: 2px solid transparent;
  transition: all 0.2s;
}
.input-wrapper:focus-within {
  border-color: rgba(79,70,229,0.1);
  background: var(--white);
  box-shadow: var(--shadow-sm);
}

.input-plus {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none;
  color: var(--slate-400); font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
.input-plus:hover { color: var(--primary); }

.voice-btn {
  position: absolute;
  right: 24px;
  bottom: calc(24px + 72px + 60px);
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary);
  border: none;
  color: var(--white); font-size: 18px;
  cursor: pointer;
  z-index: 8;
  border-radius: var(--radius-full);
  transition: background-color 0.2s, transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 8px rgba(79,70,229,0.2);
}
.voice-btn:hover {
  background: var(--primary-dark);
  transform: scale(1.05);
}
.voice-btn.recording {
  background: var(--rose);
  color: var(--white);
  animation: voice-pulse 1.1s ease-in-out infinite;
}
.voice-btn.transcribing {
  background: var(--slate-300);
  color: var(--white);
  cursor: wait;
  animation: none;
}
.voice-btn.connecting {
  background: var(--slate-500);
  cursor: wait;
}
.voice-btn .ph-spinner-gap { animation: voice-spin 0.8s linear infinite; }
.voice-btn:disabled { cursor: not-allowed; transform: none; opacity: 0.8; }
.voice-btn:focus-visible {
  outline: 3px solid rgba(99,102,241,0.28);
  outline-offset: 3px;
}
.voice-status {
  position: absolute;
  right: 76px;
  bottom: calc(24px + 72px + 70px);
  min-height: 38px;
  max-width: min(360px, calc(100vw - 110px));
  padding: 7px 8px 7px 12px;
  border-radius: var(--radius-full);
  background: rgba(31,41,55,0.86);
  font-size: 12px;
  color: var(--white);
  box-shadow: 0 10px 28px rgba(15,23,42,0.16);
  align-items: center;
  gap: 7px;
  backdrop-filter: blur(8px);
}
.voice-live-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #fb7185;
  box-shadow: 0 0 0 3px rgba(251,113,133,0.18);
}
.voice-status.finalizing .voice-live-dot,
.voice-status.transcribing .voice-live-dot { background: #cbd5e1; box-shadow: none; }
.voice-timer { color: #cbd5e1; font-variant-numeric: tabular-nums; }
.voice-meter { height: 18px; display: flex; align-items: center; gap: 2px; }
.voice-meter i {
  display: block;
  width: 2px;
  height: 100%;
  border-radius: 2px;
  background: #a5b4fc;
  transform: scaleY(var(--voice-level, 0.18));
  transition: transform 80ms linear;
}
.voice-meter i:nth-child(2), .voice-meter i:nth-child(4) { height: 70%; }
.voice-meter i:nth-child(3) { height: 45%; }
.voice-cancel-btn {
  border: 0;
  border-left: 1px solid rgba(255,255,255,0.18);
  padding: 3px 6px 3px 9px;
  color: #e0e7ff;
  background: transparent;
  font: inherit;
  cursor: pointer;
}
.voice-cancel-btn:hover { color: var(--white); }
.voice-cancel-btn:focus-visible { outline: 2px solid #c7d2fe; outline-offset: 1px; }
.voice-status.transcribing .voice-meter,
.voice-status.finalizing .voice-meter { display: none; }
@keyframes voice-spin { to { transform: rotate(360deg); } }
}
@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(244,63,94,0.25), 0 2px 8px rgba(244,63,94,0.2); }
  50% { box-shadow: 0 0 0 8px rgba(244,63,94,0), 0 2px 8px rgba(244,63,94,0.2); }
}

.input-wrapper textarea {
  flex: 1;
  padding: 8px 4px;
  font-size: 14px; font-family: inherit;
  background: transparent;
  border: none; outline: none;
  resize: none;
  max-height: 120px;
  color: var(--slate-800);
}
.input-wrapper textarea::placeholder { color: var(--slate-400); }

.send-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary);
  color: var(--white);
  border: none; border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 18px;
  transition: all 0.2s;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(79,70,229,0.2);
}
.send-btn:hover { background: var(--primary-dark); transform: scale(1.05); }
.send-btn:disabled { background: var(--slate-300); cursor: not-allowed; transform: none; box-shadow: none; }
.send-btn:disabled i { color: var(--slate-400); }

