/* ============================================================
   经贸版 ima · ima 风格聊天界面
   配色：浅底深字 · 主标签橙 · 次标签绿 · 间距统一
   ============================================================ */

:root {
  /* 基础色板 */
  --bg: #FAFAFB;
  --surface: #FFFFFF;
  --bg-soft: #F1F2F6;
  --ink: #1A1B2E;
  --ink-2: #2D2E5A;
  --muted: #6B6E85;
  --muted-2: #9B9EB5;
  --rule: #E2E4EC;
  --rule-soft: #EFF1F5;

  /* 主色 */
  --accent: #2563EB;            /* 主标签蓝 */
  --accent-soft: #EFF4FF;
  --accent-deep: #1D4ED8;
  --accent2: #2D9C68;           /* 次标签绿 */
  --accent2-soft: #E8F6EF;
  --accent2-deep: #1F7A4F;

  /* 用户气泡（蓝色调） */
  --user-bg: #2563EB;
  --user-text: #FFFFFF;
  /* AI 气泡（白） */
  --ai-bg: #FFFFFF;
  --ai-text: #1A1B2E;

  /* 状态 */
  --danger: #DC4C4C;
  --danger-soft: #FDEAEA;

  /* 字体 */
  --font-sans: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  /* 间距 */
  --space-xs: 6px;
  --space-sm: 10px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 36px;

  /* 圆角 */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;

  /* 阴影 */
  --shadow-sm: 0 1px 2px rgba(26, 27, 46, 0.04), 0 1px 3px rgba(26, 27, 46, 0.04);
  --shadow-md: 0 4px 12px rgba(26, 27, 46, 0.08);
  --shadow-lg: 0 10px 32px rgba(26, 27, 46, 0.12);
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, textarea, input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a { color: var(--accent-deep); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   整体布局
   ============================================================ */
.app {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* ============================================================
   侧边栏
   ============================================================ */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-soft);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease;
}

.sidebar-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 0;
}

.brand-logo {
  font-size: 28px;
  line-height: 1;
  flex-shrink: 0;
}

.brand-text {
  min-width: 0;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--rule-soft);
  color: var(--ink);
}

.history {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md) var(--space-sm);
}

.history-empty {
  padding: var(--space-md);
  color: var(--muted-2);
  font-size: 13px;
  text-align: center;
}

.history-item {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--ink);
  font-size: 14px;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  transition: all 0.15s ease;
  user-select: none;
}

.history-item:hover {
  background: var(--rule-soft);
}

.history-item.active {
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 500;
}

.history-item .hi-icon {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  opacity: 0.7;
}

.history-item .hi-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item .hi-del {
  opacity: 0;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--muted-2);
  cursor: pointer;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.history-item:hover .hi-del { opacity: 1; }
.history-item .hi-del:hover { color: var(--danger); background: var(--danger-soft); }

.sidebar-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--rule);
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.footer-link { color: var(--accent-deep); }
.footer-text { color: var(--muted-2); }

/* ============================================================
   主对话区
   ============================================================ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  background: var(--bg);
}

.topbar {
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 0 var(--space-lg);
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex: 1;
  min-width: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent2);
  box-shadow: 0 0 0 3px var(--accent2-soft);
  flex-shrink: 0;
}

.status-dot.loading {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation: pulse 1.2s ease-in-out infinite;
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.topbar-actions {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-primary {
  background: var(--accent-soft);
  color: var(--accent-deep);
  border: 1px solid rgba(232, 147, 43, 0.2);
}

.badge-secondary {
  background: var(--accent2-soft);
  color: var(--accent2-deep);
  border: 1px solid rgba(45, 156, 104, 0.2);
}

/* ============================================================
   欢迎屏
   ============================================================ */
.chat-area {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.welcome {
  max-width: 720px;
  margin: 0 auto;
  padding: 64px var(--space-lg) var(--space-lg);
  text-align: center;
}

.welcome-logo {
  font-size: 56px;
  line-height: 1;
  margin-bottom: var(--space-md);
}

.welcome-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
  margin-bottom: var(--space-sm);
}

.welcome-sub {
  font-size: 15px;
  color: var(--muted);
  margin-bottom: var(--space-xl);
}

.quick-questions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  justify-content: center;
  max-width: 560px;
  margin: 0 auto;
}

.quick-tag {
  padding: 8px 16px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: var(--r-pill);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s ease;
}

.quick-tag:hover {
  border-color: var(--accent);
  color: var(--accent-deep);
  background: var(--accent-soft);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   消息列表
   ============================================================ */
.messages {
  max-width: 820px;
  margin: 0 auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.msg {
  display: flex;
  gap: var(--space-md);
  align-items: flex-start;
  animation: msgIn 0.3s ease;
}

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

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}

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

.msg.user .msg-avatar {
  background: var(--accent);
  color: #fff;
}

.msg.ai .msg-avatar {
  background: var(--accent2-soft);
  color: var(--accent2-deep);
  border: 1px solid rgba(45, 156, 104, 0.2);
}

.msg-body {
  flex: 1;
  min-width: 0;
  max-width: calc(100% - 48px);
}

.msg.user .msg-body {
  display: flex;
  justify-content: flex-end;
}

.msg-bubble {
  padding: var(--space-md) var(--space-md);
  border-radius: var(--r-md);
  font-size: 14.5px;
  line-height: 1.7;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.msg.user .msg-bubble {
  background: var(--user-bg);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
  max-width: 100%;
}

.msg.ai .msg-bubble {
  background: var(--ai-bg);
  color: var(--ai-text);
  border: 1px solid var(--rule);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

/* AI 气泡内的 Markdown 样式 */
.msg.ai .msg-bubble p { margin: 0 0 10px; }
.msg.ai .msg-bubble p:last-child { margin-bottom: 0; }
.msg.ai .msg-bubble ul,
.msg.ai .msg-bubble ol { margin: 6px 0 10px; padding-left: 22px; }
.msg.ai .msg-bubble li { margin-bottom: 4px; }
.msg.ai .msg-bubble strong { font-weight: 600; color: var(--ink); }
.msg.ai .msg-bubble h1, .msg.ai .msg-bubble h2, .msg.ai .msg-bubble h3,
.msg.ai .msg-bubble h4 { font-weight: 700; margin: 14px 0 8px; line-height: 1.4; }
.msg.ai .msg-bubble h1 { font-size: 18px; }
.msg.ai .msg-bubble h2 { font-size: 17px; }
.msg.ai .msg-bubble h3 { font-size: 16px; }
.msg.ai .msg-bubble h4 { font-size: 15px; color: var(--accent-deep); }
.msg.ai .msg-bubble a { color: var(--accent-deep); text-decoration: underline; }
.msg.ai .msg-bubble code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-soft);
  color: var(--accent-deep);
  padding: 2px 6px;
  border-radius: 4px;
}
.msg.ai .msg-bubble pre {
  background: var(--bg-soft);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--r-sm);
  overflow-x: auto;
  margin: 8px 0;
  font-size: 13px;
}
.msg.ai .msg-bubble pre code {
  background: transparent;
  color: var(--ink);
  padding: 0;
}
.msg.ai .msg-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}
.msg.ai .msg-bubble th {
  background: var(--bg-soft);
  text-align: left;
  padding: 6px 10px;
  border-bottom: 2px solid var(--rule);
  font-weight: 600;
}
.msg.ai .msg-bubble td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--rule);
}
.msg.ai .msg-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding: 3px 8px;
  margin: 6px 0;
  color: var(--muted);
  background: var(--accent-soft);
  font-size: 11px;
  line-height: 1.4;
  border-radius: 0 6px 6px 0;
}

.msg-meta {
  font-size: 11px;
  color: var(--muted-2);
  margin-top: 4px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.msg.user .msg-meta { justify-content: flex-end; }

/* ============================================================
   打字指示器（loading 时）
   ============================================================ */
.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}

.typing span {
  width: 6px;
  height: 6px;
  background: var(--muted-2);
  border-radius: 50%;
  display: inline-block;
  animation: typing 1.4s ease-in-out infinite;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  background: var(--accent);
  vertical-align: middle;
  margin-left: 2px;
  animation: blink 0.9s steps(2) infinite;
}

@keyframes blink {
  to { opacity: 0; }
}

/* ============================================================
   输入框
   ============================================================ */
.composer {
  flex-shrink: 0;
  border-top: 1px solid var(--rule);
  background: var(--surface);
  padding: var(--space-md) var(--space-lg) var(--space-sm);
}

.composer-inner {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  gap: var(--space-sm);
  align-items: flex-end;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 8px 8px 8px 16px;
  transition: all 0.15s ease;
}

.composer-inner:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  max-height: 160px;
  line-height: 1.6;
  padding: 6px 0;
  font-size: 14.5px;
  color: var(--ink);
}

.input::placeholder { color: var(--muted-2); }

.send-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: var(--r-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-deep);
  transform: translateY(-1px);
}

.send-btn:disabled {
  background: var(--rule);
  color: var(--muted-2);
  cursor: not-allowed;
}

.send-btn.loading {
  background: var(--accent);
  pointer-events: none;
}

.composer-hint {
  max-width: 820px;
  margin: var(--space-sm) auto 0;
  font-size: 9px;
  color: var(--muted-2);
  text-align: center;
}

.composer-hint a { color: var(--accent-deep); }

/* ============================================================
   免责声明
   ============================================================ */
.disclaimer {
  font-size: 9px;
  color: var(--muted-2);
  text-align: center;
  padding: 3px 6px;
  background: var(--bg-soft);
  border-radius: var(--r-sm);
  border: 1px dashed var(--rule);
  line-height: 1.3;
}

.welcome-disclaimer {
  max-width: 560px;
  margin: var(--space-lg) auto 0;
}

.composer-disclaimer {
  margin-top: var(--space-sm);
}

/* ============================================================
   错误提示
   ============================================================ */
.error-banner {
  background: var(--danger-soft);
  border: 1px solid rgba(220, 76, 76, 0.2);
  color: var(--danger);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--r-md);
  font-size: 13px;
  margin-bottom: var(--space-md);
}

/* ============================================================
   遮罩 & 移动端
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 27, 46, 0.4);
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.mobile-only { display: none; }

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 20;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .mobile-only { display: inline-flex; }
  .topbar { padding: 0 var(--space-md); }
  .topbar-actions .badge { display: none; }
  .welcome { padding: 36px var(--space-md) var(--space-md); }
  .welcome-logo { font-size: 44px; }
  .welcome-title { font-size: 22px; }
  .messages { padding: var(--space-md); gap: var(--space-md); }
  .composer { padding: var(--space-sm) var(--space-md) var(--space-xs); }
  .msg-bubble { font-size: 14px; padding: 12px 14px; }
  .quick-tag { font-size: 12px; padding: 6px 12px; }
}

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }
