/* ============ 前台客服对话 · 去AI化专业风格 ============ */

/* ---------- Design Tokens ---------- */
:root {
  /* 主色：沉稳青绿，专业客服感 */
  --brand: oklch(55% 0.14 185);
  --brand-hover: oklch(50% 0.14 185);
  --brand-active: oklch(45% 0.13 185);
  --brand-soft: oklch(94% 0.05 185);
  --brand-soft-hover: oklch(90% 0.06 185);

  /* 中性色（带冷调，专业感） */
  --neutral-50: oklch(98% 0.005 220);
  --neutral-100: oklch(95% 0.008 220);
  --neutral-200: oklch(90% 0.01 220);
  --neutral-300: oklch(82% 0.012 220);
  --neutral-400: oklch(70% 0.015 220);
  --neutral-500: oklch(55% 0.018 220);
  --neutral-600: oklch(42% 0.02 220);
  --neutral-700: oklch(32% 0.02 220);
  --neutral-800: oklch(22% 0.018 220);
  --neutral-900: oklch(14% 0.015 220);

  /* 语义色 */
  --success: oklch(62% 0.16 145);
  --success-soft: oklch(94% 0.04 145);
  --warning: oklch(75% 0.15 75);
  --danger: oklch(60% 0.2 25);

  /* 表面层级 */
  --bg-page: var(--neutral-100);
  --bg-surface: #ffffff;
  --bg-surface-secondary: var(--neutral-50);
  --bg-hover: var(--neutral-100);
  --border: var(--neutral-200);
  --border-strong: var(--neutral-300);

  /* 文字 */
  --text-primary: var(--neutral-900);
  --text-secondary: var(--neutral-600);
  --text-tertiary: var(--neutral-400);
  --text-inverse: #ffffff;

  /* 阴影 */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 8px 10px -6px rgba(15, 23, 42, 0.05);

  /* 圆角 */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 999px;

  /* 间距 */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* 字号 */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 15px;
  --fs-lg: 16px;
  --fs-xl: 18px;
  --fs-2xl: 22px;

  /* 过渡 */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* 深色主题 */
[data-theme="dark"] {
  --brand: oklch(68% 0.14 185);
  --brand-hover: oklch(73% 0.14 185);
  --brand-active: oklch(63% 0.13 185);
  --brand-soft: oklch(28% 0.06 185);
  --brand-soft-hover: oklch(33% 0.07 185);

  --neutral-50: oklch(16% 0.012 220);
  --neutral-100: oklch(20% 0.015 220);
  --neutral-200: oklch(26% 0.018 220);
  --neutral-300: oklch(34% 0.02 220);
  --neutral-400: oklch(48% 0.02 220);
  --neutral-500: oklch(60% 0.018 220);
  --neutral-600: oklch(72% 0.015 220);
  --neutral-700: oklch(82% 0.012 220);
  --neutral-800: oklch(90% 0.01 220);
  --neutral-900: oklch(96% 0.008 220);

  --bg-page: oklch(12% 0.01 220);
  --bg-surface: oklch(18% 0.012 220);
  --bg-surface-secondary: oklch(22% 0.014 220);
  --bg-hover: var(--neutral-100);
  --border: var(--neutral-200);
  --border-strong: var(--neutral-300);

  --text-primary: var(--neutral-900);
  --text-secondary: var(--neutral-500);
  --text-tertiary: var(--neutral-400);
  --text-inverse: var(--neutral-900);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: var(--fs-base);
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition-base), color var(--transition-base);
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 聊天容器 ---------- */
.chat-shell {
  width: 100%;
  max-width: 860px;
  height: min(780px, calc(100vh - 48px));
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  margin: 24px auto;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-4);
}

/* ---------- 顶部导航 ---------- */
.chat-header {
  background: var(--bg-surface);
  color: var(--text-primary);
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--brand-soft);
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-logo svg { width: 20px; height: 20px; }
.brand-title {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
.brand-status {
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}
.brand-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
  box-shadow: 0 0 0 3px var(--success-soft);
}

/* 头部操作区 */
.header-actions { display: flex; align-items: center; gap: var(--space-2); }

/* 主题切换按钮 */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* 新对话按钮 */
.new-chat-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.new-chat-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.new-chat-btn svg { width: 18px; height: 18px; }

/* 人工客服按钮 */
.human-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--brand-soft);
  color: var(--brand);
  text-decoration: none;
  font-size: var(--fs-sm);
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  transition: all var(--transition-fast);
}
.human-btn:hover {
  background: var(--brand-soft-hover);
  text-decoration: none;
}
.human-btn svg { width: 14px; height: 14px; }

/* ---------- 消息区 ---------- */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
  background: var(--bg-surface-secondary);
  scroll-behavior: smooth;
}
.chat-body::-webkit-scrollbar { width: 6px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }
.chat-body::-webkit-scrollbar-thumb {
  background: var(--neutral-300);
  border-radius: 3px;
}
.chat-body::-webkit-scrollbar-thumb:hover { background: var(--neutral-400); }

/* 欢迎页 */
.welcome {
  text-align: center;
  margin: 0 auto;
  max-width: 480px;
  padding: var(--space-8) 0;
}
.welcome-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--brand-soft);
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
}
.welcome-icon svg { width: 28px; height: 28px; }
.welcome-title {
  font-size: var(--fs-xl);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
.welcome-desc {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  margin: var(--space-2) 0 var(--space-5);
  line-height: 1.7;
}

/* 快捷问题 */
.quick-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  padding: 8px 14px;
  font-size: var(--fs-sm);
  transition: all var(--transition-fast);
}
.chip::before {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--brand);
  flex-shrink: 0;
}
.chip:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
  transform: translateY(-1px);
}

/* 消息气泡 */
.msg {
  display: flex;
  margin-bottom: var(--space-4);
  align-items: flex-start;
  gap: var(--space-3);
}
.msg .avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0;
}
.msg .avatar svg { width: 16px; height: 16px; }
.msg.ai .avatar {
  background: var(--brand);
}
.msg.user {
  flex-direction: row-reverse;
}
.msg.user .avatar {
  background: var(--neutral-400);
}

.msg .bubble {
  max-width: min(72%, 520px);
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: var(--fs-base);
  line-height: 1.7;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.ai .bubble {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}
.msg.user .bubble {
  background: var(--brand);
  color: #fff;
  border-top-right-radius: 4px;
}
.msg.user .bubble a { color: #fff; text-decoration: underline; }
.msg.ai .bubble a { color: var(--brand); }

/* 消息时间 */
.msg-time {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* ---------- 输入区 ---------- */
.chat-footer {
  border-top: 1px solid var(--border);
  padding: var(--space-3) var(--space-4) var(--space-3);
  background: var(--bg-surface);
  flex-shrink: 0;
}
.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  background: var(--bg-surface-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-2);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.input-wrap:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.input-wrap textarea {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 10px;
  font-size: var(--fs-base);
  resize: none;
  outline: none;
  color: var(--text-primary);
  line-height: 1.6;
  max-height: 120px;
  min-height: 24px;
}
.input-wrap textarea::placeholder {
  color: var(--text-tertiary);
}

.send-btn {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 9px 18px;
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.send-btn:hover:not(:disabled) {
  background: var(--brand-hover);
}
.send-btn:active:not(:disabled) {
  background: var(--brand-active);
}
.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.send-btn svg { width: 14px; height: 14px; }

.footer-tip {
  text-align: center;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: var(--space-2);
}

/* ---------- 输入中动画 ---------- */
.typing {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 99;
}
.typing-bubble {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  gap: 5px;
  align-items: center;
}
.typing-bubble span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand);
  display: inline-block;
  animation: blink 1.2s infinite;
}
.typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- 响应式：平板 (768px 以下) ---------- */
@media (max-width: 768px) {
  .chat-shell {
    max-width: 100%;
    height: min(720px, calc(100vh - 32px));
    margin: 16px auto;
  }
  .chat-header { padding: var(--space-3) var(--space-4); }
  .chat-body { padding: var(--space-5); }
  .msg .bubble { max-width: min(78%, 460px); }
}

/* ---------- 响应式：手机 (600px 以下) ---------- */
@media (max-width: 600px) {
  body { padding: 0; }
  .chat-shell {
    height: 100vh;
    border-radius: 0;
    margin: 0;
    border: none;
    box-shadow: none;
  }
  .chat-header {
    padding: var(--space-3);
    padding-top: calc(var(--space-3) + env(safe-area-inset-top, 0px));
  }
  .brand-title { font-size: var(--fs-base); }
  .brand-status { font-size: 11px; }
  .brand-logo { width: 36px; height: 36px; }
  .brand-logo svg { width: 18px; height: 18px; }

  .human-btn {
    padding: 7px 12px;
    font-size: var(--fs-xs);
  }
  .human-btn svg { width: 12px; height: 12px; }
  .human-btn span { display: none; }

  .theme-toggle { width: 34px; height: 34px; }
  .new-chat-btn { width: 34px; height: 34px; }

  .chat-body { padding: var(--space-4); }
  .welcome { padding: var(--space-6) 0; }
  .welcome-icon { width: 48px; height: 48px; }
  .welcome-icon svg { width: 24px; height: 24px; }
  .welcome-title { font-size: var(--fs-lg); }

  .msg .bubble { max-width: 82%; font-size: var(--fs-sm); }
  .msg .avatar { width: 30px; height: 30px; }
  .msg .avatar svg { width: 14px; height: 14px; }
  .msg { gap: var(--space-2); margin-bottom: var(--space-3); }

  .chat-footer {
    padding: var(--space-2) var(--space-3);
    padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
  }
  .send-btn {
    padding: 9px 14px;
    font-size: 0;
  }
  .send-btn svg { width: 16px; height: 16px; }

  .chip { padding: 7px 12px; font-size: var(--fs-xs); }
}

/* ---------- 响应式：大屏 (1024px 以上) ---------- */
@media (min-width: 1024px) {
  .chat-shell {
    max-width: 900px;
    height: min(820px, calc(100vh - 60px));
  }
  .chat-header { padding: var(--space-5) var(--space-6); }
  .chat-body { padding: var(--space-6) var(--space-8); }
  .chat-footer { padding: var(--space-4) var(--space-6) var(--space-3); }
}

/* ---------- 无障碍：减少动画 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- 焦点可见 ---------- */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
