/* ── Tokens ── */
:root {
  --bg: #f3f3f3;
  --surface: #ffffff;
  --fg: #111111;
  --fg-secondary: #3d3d3d;
  --muted: #767676;
  --border: #e5e5e5;
  --accent: #2B5EA7;
  --accent-hover: #1e4a8a;

  --user-bubble: #2B5EA7;
  --user-fg: #ffffff;
  --bot-bubble: #ffffff;
  --bot-avatar: #8aa4c8;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 16px;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Shell ── */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.header-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; font-weight: 600;
  flex-shrink: 0;
}
.header-info { flex: 1; min-width: 0; }
.header-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}
.header-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #52c41a;
  margin-right: 4px;
  vertical-align: middle;
}

/* ── Chat Area ── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 16px 8px;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.02'/%3E%3C/svg%3E");
}

/* ── Time Divider ── */
.time-divider {
  text-align: center;
  margin: 12px 0 10px;
  font-size: 11px;
  color: var(--muted);
}

/* ── Welcome ── */
.welcome-section {
  padding: 36px 4px 20px;
  animation: fadeIn 0.4s ease;
}
.welcome-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.welcome-icon-wrap {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.welcome-icon-wrap svg { width: 24px; height: 24px; fill: #fff; }
.welcome-greeting {
  font-size: 20px;
  font-weight: 600;
}
.welcome-desc {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.55;
  max-width: 40ch;
}

/* ── Quick Questions ── */
.quick-questions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px 4px 8px;
  animation: fadeIn 0.5s ease;
}
.quick-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 14px 12px;
  cursor: pointer;
  font-family: var(--font);
  text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.quick-card:hover {
  border-color: #d0d0d0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.quick-card:active {
  border-color: #c0c0c0;
  transform: scale(0.98);
}
.quick-card-icon {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 8px;
}
.quick-card-icon svg { width: 18px; height: 18px; }
.quick-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.3;
  margin-bottom: 2px;
}
.quick-card-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* ── Messages ── */
.msg {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  max-width: 82%;
  opacity: 0;
  animation: msgIn 0.25s ease forwards;
}
.msg + .msg { margin-top: 2px; }
.msg--user + .msg--bot,
.msg--bot + .msg--user { margin-top: 12px; }

.msg--bot { align-self: flex-start; flex-direction: column; }
.msg--user { align-self: flex-end; flex-direction: row-reverse; margin-left: auto; }

.msg-row {
  display: flex;
  gap: 8px;
}

.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  color: #fff;
  margin-top: 2px;
}
.msg--bot .msg-avatar { background: var(--bot-avatar); }
.msg--user .msg-avatar { background: var(--accent); }

.msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.6;
  word-break: break-word;
}
.msg--bot .msg-bubble {
  background: var(--bot-bubble);
  color: var(--fg);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  border-top-left-radius: 4px;
}
.msg--user .msg-bubble {
  background: var(--user-bubble);
  color: var(--user-fg);
  border-top-right-radius: 4px;
}

.msg-bubble strong { font-weight: 600; }
.msg-bubble ul, .msg-bubble ol {
  margin: 6px 0;
  padding-left: 18px;
}
.msg-bubble li { margin-bottom: 3px; }

/* ── Typing indicator ── */
.typing-indicator {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  max-width: 82%;
  animation: fadeIn 0.2s ease;
}
.typing-indicator .msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bot-avatar);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}
.typing-dots {
  background: var(--bot-bubble);
  padding: 12px 16px;
  border-radius: var(--radius);
  border-top-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  display: flex;
  gap: 4px;
  align-items: center;
}
.typing-dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #b8b8b8;
  animation: typingPulse 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

/* ── Input Bar ── */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.input-wrap { flex: 1; }
.input-field {
  width: 100%;
  min-height: 40px;
  max-height: 120px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 15px;
  font-family: var(--font);
  color: var(--fg);
  background: var(--bg);
  outline: none;
  resize: none;
  line-height: 1.4;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-field:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(43,94,167,0.08);
}
.input-field::placeholder { color: #8c8c8c; }

.send-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled {
  background: #c8d6e8;
  cursor: default;
  opacity: 0.6;
}
.send-btn svg { width: 18px; height: 18px; fill: currentColor; }

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes typingPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

@media (min-width: 481px) {
  .app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* ── Related Questions ── */
.related-questions {
  padding: 4px 0 12px 42px;
  animation: fadeIn 0.3s ease;
}
.related-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}
.related-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.related-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 6px 14px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.related-btn:hover {
  background: #f0f5ff;
  border-color: var(--accent);
}
.related-btn:active {
  background: #e0ebff;
}

/* ── Sharer Popup ── */
.sharer-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fadeIn 0.3s ease;
}
.sharer-popup {
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px;
  width: 320px;
  max-width: 90vw;
  text-align: center;
  position: relative;
  box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}
.sharer-popup-close {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 18px;
  color: #999;
  cursor: pointer;
  padding: 4px;
}
.sharer-popup-close:hover { color: #333; }
.sharer-popup-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--fg);
}
.sharer-popup-qr {
  width: 180px;
  height: 180px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: cover;
  margin-bottom: 12px;
}
.sharer-popup-wechat {
  font-size: 15px;
  color: var(--fg);
  margin-bottom: 8px;
}
.sharer-popup-remark {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.5;
}
.sharer-popup-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 32px;
  font-size: 15px;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s;
}
.sharer-popup-btn:hover { background: var(--accent-hover); }
