/* ── CSS Custom Properties ── */
:root {
  --color-primary: #00C9C3;
  --color-secondary: #0094F4;
  --color-accent: #667eea;
  --color-danger: #e55;
  --color-primary-rgb: 0, 201, 195;
  --color-secondary-rgb: 0, 148, 244;
  --gradient-primary: linear-gradient(135deg, #00C9C3, #0094F4);
  --color-text: #333;
  --color-text-muted: #999;
  --color-text-faint: #bbb;
  --color-surface: rgba(255, 255, 255, 0.65);
  --color-border: rgba(255, 255, 255, 0.5);
}

/* ── Reset & Body ── */
* { margin: 0; padding: 0; box-sizing: border-box; }

@keyframes float1 { 0%,100% { transform: translate(0,0); } 50% { transform: translate(30px,-20px); } }
@keyframes float2 { 0%,100% { transform: translate(0,0); } 50% { transform: translate(-20px,30px); } }
@keyframes float3 { 0%,100% { transform: translate(0,0); } 50% { transform: translate(15px,25px); } }

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #eef2f7;
  background-image:
    radial-gradient(ellipse at 15% 20%, rgba(var(--color-primary-rgb), 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 25%, rgba(var(--color-secondary-rgb), 0.10) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(102, 126, 234, 0.08) 0%, transparent 50%);
  color: var(--color-text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
/* floating orbs */
body::before, body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  filter: blur(60px);
}
body::before {
  width: 400px; height: 400px;
  top: -80px; left: -60px;
  background: radial-gradient(circle, rgba(var(--color-primary-rgb),0.15), transparent 70%);
  animation: float1 12s ease-in-out infinite;
}
body::after {
  width: 350px; height: 350px;
  bottom: -60px; right: -40px;
  background: radial-gradient(circle, rgba(var(--color-secondary-rgb),0.12), transparent 70%);
  animation: float2 15s ease-in-out infinite;
}
body > * { position: relative; z-index: 1; }

/* ── Header ── */
.header {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 1px 12px rgba(0, 0, 0, 0.04);
  flex-shrink: 0;
}
.header .logo { height: 26px; }
.header .logo-dark { display: none; height: 22px; }
.mobile-menu-btn {
  display: none;
  align-items: center;
  gap: 6px;
  margin-right: 10px;
  padding: 0 12px;
  height: 34px;
  border: 1px solid rgba(var(--color-secondary-rgb), 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  color: #4f647d;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  flex-shrink: 0;
}
.mobile-menu-btn strong {
  font: inherit;
}
.header .title {
  margin-left: 16px;
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text);
}
.header .model-select {
  margin-left: auto;
  padding: 5px 12px;
  border: 1px solid rgba(79, 178, 207, 0.25);
  border-radius: 16px;
  font-size: 12px;
  color: #666;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  outline: none;
}
.header .model-select:focus { border-color: var(--color-primary); }

/* ── Main Layout ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 0 16px;
  overflow: hidden;
  min-width: 0;
}

/* ── Welcome Animations ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}

/* ── Welcome ── */
.welcome {
  text-align: center;
  padding: 20px 0 12px;
  flex-shrink: 0;
}
.welcome-hero {
  position: relative;
  width: 150px;
  height: 150px;
  margin: 0 auto -14px;
  animation: scaleIn 0.5s ease-out;
}
.welcome-hero canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.hero-brand {
  margin: 0 auto 4px;
  opacity: 0;
  transition: opacity 0.3s ease;
  text-align: center;
  height: 40px;
}
.hero-brand.visible { opacity: 1; }
.hero-brand canvas {
  display: block;
  margin: 0 auto;
}
.welcome h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 6px;
  animation: fadeInUp 0.5s ease-out 0.4s both;
}
.welcome p {
  font-size: 14px;
  color: var(--color-text-muted);
  animation: fadeInUp 0.5s ease-out 0.55s both;
}

/* ── Quick Questions ── */
.quick-questions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  padding-bottom: 20px;
  flex-shrink: 0;
}
.quick-btn {
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--color-border);
  padding: 10px 16px;
  font-size: 13px;
  color: #666;
  cursor: pointer;
  transition: all .25s cubic-bezier(0.22, 1, 0.36, 1);
  max-width: 280px;
  text-align: left;
  line-height: 1.4;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  animation: fadeInUp 0.4s ease-out both;
}
.quick-btn:nth-child(1) { animation-delay: 0.4s; }
.quick-btn:nth-child(2) { animation-delay: 0.5s; }
.quick-btn:nth-child(3) { animation-delay: 0.6s; }
.quick-btn:nth-child(4) { animation-delay: 0.7s; }
.quick-btn:nth-child(5) { animation-delay: 0.8s; }
.quick-btn:hover {
  border-color: rgba(var(--color-primary-rgb), 0.4);
  color: var(--color-primary);
  background: rgba(255, 255, 255, 0.8);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(var(--color-primary-rgb), 0.12);
}

/* ── Chat Area ── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  scroll-behavior: smooth;
}
.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-thumb { background: #d0d0d0; border-radius: 2px; }

.msg { display: flex; margin-bottom: 16px; gap: 10px; }
.msg.user { flex-direction: row-reverse; }

.msg .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #fff;
}
.msg.assistant .avatar { background: var(--gradient-primary); }
.msg.user .avatar { background: var(--color-accent); }

.msg .bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.assistant .bubble {
  background: var(--color-surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-top-left-radius: 4px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}
.msg.user .bubble {
  background: var(--gradient-primary);
  color: #fff;
  border-top-right-radius: 4px;
}

/* ── Thinking Steps ── */
.thinking-steps {
  margin-bottom: 12px;
  max-height: 120px;
  overflow-y: auto;
  background: rgba(0, 148, 244, 0.04);
  border-radius: 8px;
  padding: 8px 12px;
  border-left: 3px solid var(--color-primary, #0094F4);
}
.thinking-steps::-webkit-scrollbar { width: 3px; }
.thinking-steps::-webkit-scrollbar-thumb { background: #ddd; border-radius: 2px; }
.thinking-steps.collapsed .thinking-step { display: none; }
.thinking-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--color-text-faint);
  cursor: pointer;
  padding: 4px 0;
  user-select: none;
}
.thinking-toggle:hover { color: var(--color-primary); }
.thinking-steps.collapsed .thinking-toggle,
.thinking-steps.collapsible .thinking-toggle { display: flex; }
.thinking-toggle .arrow {
  display: inline-block;
  transition: transform 0.2s;
  font-size: 10px;
}
.thinking-steps.collapsed .thinking-toggle .arrow { transform: rotate(-90deg); }
.thinking-step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 12px;
  color: var(--color-text-muted);
  animation: fadeIn 0.3s ease;
}
.thinking-step.active {
  color: var(--color-primary, #0094F4);
  font-weight: 500;
}
.thinking-step.done {
  color: var(--color-text-faint, #bbb);
}
.thinking-step.done .thinking-spinner {
  display: none;
}
.bubble-thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-top: 8px;
  background: rgba(0, 148, 244, 0.04);
  border-radius: 8px;
  border-left: 3px solid var(--color-primary, #0094F4);
  font-size: 12px;
  color: var(--color-primary, #0094F4);
  font-weight: 500;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Chart Loading Placeholder (流式阶段) ── */
.chart-loading-placeholder {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  margin: 8px 0;
  background: rgba(0, 148, 244, 0.04);
  border: 1px dashed rgba(0, 148, 244, 0.25);
  border-radius: 10px;
  animation: fadeIn 0.3s ease;
}
.chart-loading-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.chart-loading-text {
  font-size: 13px;
  color: var(--color-primary, #0094F4);
  font-weight: 500;
}
.thinking-step .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-primary);
  flex-shrink: 0;
}
.thinking-step.active .dot {
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}
.thinking-step.done .dot {
  background: #ccc;
  animation: none;
}
.thinking-step .step-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 600px;
}

/* ── Streaming Cursor ── */
.streaming .bubble::after { display: none; }
.streaming .bubble-pending::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--color-primary);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursorBlink 0.8s infinite;
}
.bubble-rendered { white-space: normal; }
.bubble-pending { white-space: pre-wrap; }
@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── Chart/Table generating indicator in main chat ── */
.chat-gen-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  margin-top: 8px;
  background: linear-gradient(135deg, #f0f7ff 0%, #e8f4fd 50%, #f0f0ff 100%);
  border-radius: 10px;
  border: 1px solid rgba(0, 148, 244, 0.12);
  animation: chatGenFadeIn 0.3s ease;
}
@keyframes chatGenFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-gen-icon {
  flex-shrink: 0;
  color: var(--color-primary, #0094F4);
  animation: chatGenPulse 2s ease-in-out infinite;
}
@keyframes chatGenPulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}
.chat-gen-text {
  font-size: 13px;
  font-weight: 500;
  color: #555;
  letter-spacing: 0.3px;
}
.chat-gen-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-left: 2px;
}
.chat-gen-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-primary, #0094F4);
  animation: chatGenBounce 1.4s ease-in-out infinite;
}
.chat-gen-dots span:nth-child(2) { animation-delay: 0.16s; }
.chat-gen-dots span:nth-child(3) { animation-delay: 0.32s; }
@keyframes chatGenBounce {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.7); }
  40% { opacity: 1; transform: scale(1); }
}

/* ── Input Area ── */
.input-area {
  flex-shrink: 0;
  padding: 12px 0 20px;
}
.input-box {
  background: #fff;
  border-radius: 12px;
  border: 1px solid transparent;
  background-image: linear-gradient(#fff, #fff), linear-gradient(90deg, var(--color-primary), var(--color-secondary));
  background-origin: border-box;
  background-clip: padding-box, border-box;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}
.input-box textarea {
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  font-family: inherit;
  color: var(--color-text);
  background: transparent;
  min-height: 24px;
  max-height: 120px;
  line-height: 1.5;
}
.input-box textarea::placeholder { color: #ccc; }

.input-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.input-tags { display: flex; gap: 8px; }
.tag {
  font-size: 12px;
  padding: 3px 12px;
  border-radius: 13px;
  border: 1px solid #e6e8f2;
  color: var(--color-text-muted);
  cursor: default;
  user-select: none;
}
.tag.active { border-color: var(--color-primary); color: #169ebb; }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--gradient-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .2s;
  flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.send-btn svg { width: 18px; height: 18px; fill: #fff; }
.send-btn.stopping { background: linear-gradient(135deg, #ef4444, #f59e0b); }
.send-btn.stopping:disabled { opacity: 1; cursor: pointer; }
.send-btn .stop-icon { display: none; width: 14px; height: 14px; background: #fff; border-radius: 2px; }
.send-btn.stopping svg { display: none; }
.send-btn.stopping .stop-icon { display: block; }

/* ── Footer ── */
.footer {
  text-align: center;
  padding: 0 0 12px;
  font-size: 11px;
  color: var(--color-text-faint);
  flex-shrink: 0;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .main { max-width: 100%; padding: 0 8px; }
  .welcome { padding: 32px 0 16px; }
  .welcome h2 { font-size: 18px; }
  .quick-questions { gap: 6px; }
  .quick-btn { font-size: 12px; padding: 8px 12px; }
  .msg .bubble { max-width: 90%; font-size: 13px; }
  .echart-container { min-height: 240px; height: 280px; }
}
@media (max-width: 499px) {
  .header {
    padding: 0 12px;
  }
  .mobile-menu-btn {
    display: inline-flex;
  }
  .header .title {
    display: none;
  }
}

body.force-mobile-sidebar .header {
  padding: 0 12px;
}

body.force-mobile-sidebar .mobile-menu-btn {
  display: inline-flex;
}

body.force-mobile-sidebar .header .title {
  display: none;
}
@media (min-width: 641px) and (max-width: 1024px) {
  .main { max-width: 85%; }
}

/* ── Markdown in Bubble ── */
.msg.assistant .bubble { white-space: normal; }
.msg.assistant .bubble p { margin: 0 0 8px; }
.msg.assistant .bubble p:last-child { margin-bottom: 0; }

/* ── Table Wrapper with Export ── */
.table-wrapper {
  position: relative;
  margin: 8px 0;
}
.table-export-btn {
  position: absolute;
  top: -2px;
  right: 0;
  width: 26px;
  height: 26px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  transition: all 0.2s;
  z-index: 1;
}
.table-export-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: #fff;
}

.msg.assistant .bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 0;
  font-size: 13px;
}
.msg.assistant .bubble th,
.msg.assistant .bubble td {
  border: 1px solid #e0e0e0;
  padding: 6px 10px;
  text-align: left;
}
.msg.assistant .bubble th {
  background: #f5f6fa;
  font-weight: 600;
  color: #555;
}
.msg.assistant .bubble tr:hover { background: #fafbfe; }
.msg.assistant .bubble code {
  background: #f0f1f5;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
  font-family: "SF Mono", "Menlo", monospace;
}
.msg.assistant .bubble pre {
  background: #f5f6fa;
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg.assistant .bubble pre code {
  background: none;
  padding: 0;
}
.msg.assistant .bubble ul,
.msg.assistant .bubble ol {
  padding-left: 20px;
  margin: 6px 0;
}
.msg.assistant .bubble li { margin: 2px 0; }
.msg.assistant .bubble h1,
.msg.assistant .bubble h2,
.msg.assistant .bubble h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 10px 0 4px;
}
.msg.assistant .bubble blockquote {
  border-left: 3px solid var(--color-primary);
  padding-left: 10px;
  color: #666;
  margin: 6px 0;
}
.msg.assistant .bubble hr {
  border: none;
  border-top: 1px solid #eee;
  margin: 8px 0;
}

/* ── Search Confirm Card ── */
.search-confirm {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 42px 16px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(var(--color-primary-rgb), 0.25);
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(var(--color-primary-rgb), 0.08);
  animation: fadeIn 0.3s ease;
}
.search-confirm-text {
  flex: 1;
  font-size: 13px;
  line-height: 1.6;
  color: #555;
}
.search-confirm-text .search-icon {
  margin-right: 4px;
}
.search-confirm-text small {
  color: #999;
}
.search-confirm-btn {
  flex-shrink: 0;
  padding: 7px 18px;
  border: none;
  border-radius: 8px;
  background: var(--gradient-primary);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
  white-space: nowrap;
}
.search-confirm-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}
.search-confirm-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
