:root {
  color-scheme: light;
  --brand: #2547c8;
  --brand-dark: #18349c;
  --brand-soft: #eef2ff;
  --ink: #182033;
  --muted: #687087;
  --line: #e6e9f0;
  --paper: #ffffff;
  --canvas: #f3f5f8;
  --mint: #1b9a6c;
  --warm: #f4a340;
  --shadow: 0 22px 70px rgba(29, 39, 72, 0.14);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

button, textarea { font: inherit; }
button { cursor: pointer; }

.page-backdrop {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(130deg, rgba(37, 71, 200, 0.08), transparent 42%),
    radial-gradient(circle at 88% 86%, rgba(27, 154, 108, 0.08), transparent 24%);
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(900px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--paper);
}

.topbar {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  padding: max(12px, env(safe-area-inset-top)) 20px 12px;
  color: #fff;
  background: var(--brand);
  box-shadow: 0 2px 16px rgba(24, 52, 156, 0.18);
}

.topbar-copy { min-width: 0; flex: 1; }
.topbar-copy strong { display: block; font-size: 16px; letter-spacing: 0.02em; }
.topbar-copy > span { display: flex; align-items: center; gap: 7px; margin-top: 3px; color: rgba(255,255,255,.78); font-size: 12px; }
.topbar-copy i, .status-pill i { width: 7px; height: 7px; border-radius: 50%; background: #54d79c; box-shadow: 0 0 0 3px rgba(84, 215, 156, .17); }

.assistant-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 30%;
  color: var(--brand);
  background: #fff;
  box-shadow: 0 6px 18px rgba(24, 52, 156, .13);
}
.assistant-avatar span { font-weight: 900; font-family: Georgia, "Songti SC", serif; }
.assistant-avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
.assistant-avatar__text { display: block; max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: -.08em; }
.assistant-avatar--small { width: 42px; height: 42px; }
.assistant-avatar--small span { font-size: 21px; }
.assistant-avatar--small .size-2 { font-size: 16px; }
.assistant-avatar--small .size-3, .assistant-avatar--small .size-4 { font-size: 13px; }
.assistant-avatar--hero { width: 102px; height: 102px; border: 7px solid var(--brand-soft); }
.assistant-avatar--hero span { font-size: 46px; }
.assistant-avatar--hero .size-2 { font-size: 33px; }
.assistant-avatar--hero .size-3 { font-size: 26px; }
.assistant-avatar--hero .size-4 { font-size: 21px; }
.assistant-avatar--bubble { width: 34px; height: 34px; margin-top: 2px; border-radius: 12px; border: 1px solid var(--line); }
.assistant-avatar--bubble span { font-size: 17px; }
.assistant-avatar--bubble .size-2 { font-size: 13px; }
.assistant-avatar--bubble .size-3, .assistant-avatar--bubble .size-4 { font-size: 11px; }

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  color: #fff;
  background: transparent;
  transition: background .2s, transform .2s;
}
.icon-button:hover { background: rgba(255,255,255,.12); }
.icon-button:active { transform: scale(.93); }
.icon-button svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.back-button, .clear-button { visibility: hidden; }
.app-shell.has-messages .back-button, .app-shell.has-messages .clear-button { visibility: visible; }

.conversation {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  padding: 0 max(18px, calc((100% - 760px) / 2));
}

.welcome { padding: 38px 0 30px; text-align: center; animation: appear .4s ease both; }
.welcome-mark { position: relative; display: inline-block; }
.status-pill {
  position: absolute;
  right: -24px;
  bottom: 7px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  padding: 6px 9px;
  border: 1px solid #dce4e1;
  border-radius: 999px;
  color: #3b6859;
  background: rgba(255,255,255,.96);
  box-shadow: 0 4px 14px rgba(37, 63, 54, .1);
  font-size: 11px;
  font-weight: 700;
}
.status-pill i { width: 6px; height: 6px; }
.eyebrow { margin: 18px 0 7px; color: var(--brand); font-size: 13px; font-weight: 800; letter-spacing: .1em; }
.welcome h1 { margin: 0; font-size: clamp(25px, 5vw, 36px); line-height: 1.24; letter-spacing: -.025em; }
.lead { margin: 10px auto 0; color: var(--muted); font-size: 14px; line-height: 1.65; }

.trust-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 18px; margin: 22px 0 28px; color: #6b7280; font-size: 12px; }
.trust-row span { display: inline-flex; align-items: center; gap: 5px; }
.trust-row svg { width: 14px; fill: none; stroke: var(--mint); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.quick-section { text-align: left; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.section-heading span { font-size: 15px; font-weight: 800; }
.section-heading small { color: #9aa1b2; font-size: 11px; }
.quick-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px; }
.quick-button {
  min-height: 82px;
  padding: 13px 10px;
  border: 1px solid var(--line);
  border-radius: 15px;
  color: var(--ink);
  background: #fff;
  text-align: left;
  transition: transform .2s, border-color .2s, box-shadow .2s, background .2s;
}
.quick-button:hover { transform: translateY(-2px); border-color: #bac6f1; background: #fbfcff; box-shadow: 0 8px 20px rgba(39, 59, 120, .09); }
.quick-button:active { transform: translateY(0) scale(.98); }
.quick-button span { display: block; margin-bottom: 8px; font-size: 22px; }
.quick-button strong { font-size: 13px; }

.contact-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  padding: 13px 14px;
  border-radius: 15px;
  color: #243148;
  background: #f6f7f9;
  text-align: left;
}
.contact-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; color: var(--mint); background: #e8f7f1; }
.contact-icon svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.contact-card small, .contact-card strong { display: block; }
.contact-card small { margin-bottom: 2px; color: var(--muted); font-size: 11px; }
.contact-card strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.contact-note { color: #8b91a1; font-size: 11px; }

.social-card { margin-top: 12px; padding: 15px; border: 1px solid #e4e8f1; border-radius: 15px; background: #fff; text-align: left; }
.social-card__heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.social-card__heading span, .social-card__heading small { display: block; }
.social-card__heading span { color: #2c3955; font-size: 13px; font-weight: 800; }
.social-card__heading small { margin-top: 3px; color: #8a93a5; font-size: 10px; }
.social-card__heading em { padding: 5px 8px; border-radius: 999px; color: #4b629d; background: #f0f4ff; font-size: 10px; font-style: normal; font-weight: 800; white-space: nowrap; }
.social-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.social-account { display: grid; gap: 10px; min-width: 0; padding: 10px; border: 1px solid #e8ebf2; border-radius: 12px; background: #fbfcfe; }
.social-account__meta { display: flex; align-items: center; gap: 7px; min-width: 0; }
.social-account__mark { display: grid; place-items: center; width: 25px; height: 25px; flex: 0 0 auto; border-radius: 8px; color: var(--brand); background: var(--brand-soft); font-size: 12px; font-weight: 900; }
.social-account__meta div { min-width: 0; }
.social-account__meta strong, .social-account__meta small { display: block; }
.social-account__meta strong { color: #34405a; font-size: 11px; }
.social-account__meta small { overflow: hidden; margin-top: 2px; color: #8a93a5; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.social-account__qr { display: grid; place-items: center; width: 100%; aspect-ratio: 1; overflow: hidden; border: 1px dashed #d6ddeb; border-radius: 9px; color: #9aa3b3; background: #fff; text-align: center; font-size: 10px; line-height: 1.45; }
.social-account__qr img { width: 100%; height: 100%; object-fit: cover; }

.contribute-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 13px;
  margin-top: 16px;
  padding: 17px;
  border: 1px solid var(--brand);
  border-radius: 18px;
  color: #fff;
  background: var(--brand);
  box-shadow: 0 14px 28px rgba(37, 71, 200, .22);
  text-align: left;
}
.contribute-card__icon { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid rgba(255,255,255,.3); border-radius: 13px; color: #fff; background: rgba(255,255,255,.15); }
.contribute-card__icon svg { width: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.contribute-card__copy { min-width: 0; }
.contribute-card__eyebrow { display: block; margin-bottom: 5px; color: rgba(255,255,255,.78); font-size: 10px; font-weight: 900; letter-spacing: .12em; }
.submission-modal__eyebrow { display: block; margin-bottom: 4px; color: var(--brand); font-size: 10px; font-weight: 800; letter-spacing: .11em; }
.contribute-card strong { display: block; font-size: 16px; line-height: 1.35; letter-spacing: -.01em; }
.contribute-card p { margin: 5px 0 0; color: rgba(255,255,255,.8); font-size: 12px; line-height: 1.55; }
.contribute-button, .submit-submission-button, .outline-submission-button {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 800;
  transition: transform .18s, background .18s, border-color .18s;
}
.contribute-button { display: inline-flex; align-items: center; gap: 8px; border: 1px solid rgba(255,255,255,.88); color: var(--brand-dark); background: #fff; box-shadow: 0 6px 15px rgba(20, 34, 112, .2); white-space: nowrap; }
.contribute-button:hover { background: #edf1ff; }
.contribute-button__plus { display: grid; place-items: center; width: 19px; height: 19px; border-radius: 50%; color: #fff; background: var(--brand); font-size: 16px; line-height: 1; }
.submit-submission-button { border: 0; color: #fff; background: var(--brand); box-shadow: 0 5px 14px rgba(37, 71, 200, .17); }
.submit-submission-button:hover { background: var(--brand-dark); }
.contribute-button:active, .submit-submission-button:active { transform: scale(.97); }
.outline-submission-button { border: 1px solid #d9deea; color: #59647c; background: #fff; }
.outline-submission-button:hover { border-color: #b4c0e6; background: #f8faff; }

.submission-overlay {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: 18px;
  background: rgba(17, 28, 57, .46);
  backdrop-filter: blur(4px);
}
.submission-overlay[hidden] { display: none; }
.submission-modal {
  width: min(560px, 100%);
  max-height: min(800px, calc(100dvh - 36px));
  overflow: auto;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(12, 24, 58, .28);
  animation: modal-in .2s ease both;
}
.submission-modal__header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 23px 24px 18px; border-bottom: 1px solid var(--line); }
.submission-modal__header h2 { margin: 0; font-size: 21px; letter-spacing: -.02em; }
.submission-modal__header p { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.modal-close { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 auto; padding: 0; border: 0; border-radius: 10px; color: #65708a; background: #f3f5f9; font-size: 23px; line-height: 1; }
.modal-close:hover { color: #263653; background: #e9edf6; }
.submission-form { padding: 20px 24px 23px; }
.submission-form label { display: grid; gap: 7px; margin-bottom: 15px; color: #2d3953; font-size: 12px; font-weight: 800; }
.submission-form input, .submission-form textarea {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid #dfe4ee;
  border-radius: 10px;
  outline: 0;
  color: var(--ink);
  background: #fbfcfe;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.55;
  resize: vertical;
  transition: border-color .18s, box-shadow .18s, background .18s;
}
.submission-form input:focus, .submission-form textarea:focus { border-color: #8296d9; background: #fff; box-shadow: 0 0 0 3px rgba(37, 71, 200, .1); }
.submission-form__grid { display: grid; grid-template-columns: 1fr 1.35fr; gap: 12px; }
.submission-privacy { margin: -2px 0 17px; padding: 10px 11px; border-radius: 9px; color: #65708a; background: #f6f8fc; font-size: 11px; line-height: 1.55; }
.submission-form__actions { display: flex; justify-content: flex-end; gap: 9px; }

.message-list { padding-top: 24px; }
.message-row { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 18px; animation: slide-up .28s ease both; }
.message-row.user { flex-direction: row-reverse; }
.message-stack { max-width: min(80%, 620px); }
.bubble { padding: 12px 15px; border-radius: 18px; font-size: 14px; line-height: 1.72; white-space: pre-wrap; word-break: break-word; }
.assistant .bubble { border: 1px solid #e8eaf1; border-bottom-left-radius: 6px; background: #f7f8fa; }
.user .bubble { border-bottom-right-radius: 6px; color: #fff; background: var(--brand); }
.message-meta { margin-top: 5px; color: #9aa1b2; font-size: 10px; }
.user .message-meta { text-align: right; }
.related { display: flex; flex-wrap: wrap; gap: 7px; margin: 9px 0 0; }
.related button {
  padding: 7px 10px;
  border: 1px solid #dce2f7;
  border-radius: 999px;
  color: #3e559c;
  background: #f7f9ff;
  font-size: 11px;
  transition: background .2s, border-color .2s;
}
.related button:hover { border-color: #aebcea; background: #eef2ff; }
.answer-images { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-top: 8px; }
.answer-images img { width: 100%; max-height: 190px; border: 1px solid #e2e6ee; border-radius: 10px; object-fit: cover; background: #f2f4f8; }

.typing-row { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 18px; }
.typing-row[hidden] { display: none; }
.typing-bubble { display: flex; gap: 5px; padding: 15px 16px; border: 1px solid var(--line); border-radius: 18px 18px 18px 6px; background: #f7f8fa; }
.typing-bubble i { width: 6px; height: 6px; border-radius: 50%; background: #8d95a8; animation: bounce 1s infinite ease-in-out; }
.typing-bubble i:nth-child(2) { animation-delay: .12s; }
.typing-bubble i:nth-child(3) { animation-delay: .24s; }

.composer-wrap {
  position: relative;
  z-index: 3;
  padding: 8px max(18px, calc((100% - 760px) / 2)) max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(14px);
}
.announcement { margin: 0 0 7px; overflow: hidden; color: #8a6b2e; font-size: 11px; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.announcement:empty { display: none; }
.composer { display: flex; align-items: flex-end; gap: 9px; padding: 5px 5px 5px 14px; border: 1px solid #dfe3ec; border-radius: 17px; background: #f7f8fa; transition: border-color .2s, box-shadow .2s, background .2s; }
.composer:focus-within { border-color: #9aacdf; background: #fff; box-shadow: 0 0 0 4px rgba(37, 71, 200, .08); }
.composer textarea { min-height: 40px; max-height: 116px; flex: 1; resize: none; padding: 10px 0 8px; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 14px; line-height: 1.45; }
.composer textarea::placeholder { color: #9ba2b1; }
.send-button { display: grid; place-items: center; width: 42px; height: 42px; flex: 0 0 auto; padding: 0; border: 0; border-radius: 13px; color: #fff; background: var(--brand); transition: transform .2s, opacity .2s, background .2s; }
.send-button:hover { background: var(--brand-dark); }
.send-button:active { transform: scale(.94); }
.send-button:disabled { cursor: default; opacity: .35; }
.send-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.footer-note { margin: 6px 0 0; color: #a0a6b4; font-size: 10px; text-align: center; }
.admin-link, .footer-link { color: #7380a6; text-decoration: none; }
.footer-link { padding: 0; border: 0; background: transparent; font-size: inherit; }
.admin-link:hover, .footer-link:hover { color: var(--brand); text-decoration: underline; }

.toast { position: fixed; z-index: 40; left: 50%; bottom: 98px; transform: translateX(-50%); max-width: calc(100vw - 40px); padding: 10px 14px; border-radius: 12px; color: #fff; background: rgba(24, 32, 51, .9); box-shadow: 0 8px 30px rgba(0,0,0,.2); font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@keyframes appear { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .6; } 30% { transform: translateY(-4px); opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }

@media (min-width: 920px) {
  body { padding: 24px; }
  .app-shell { height: calc(100dvh - 48px); min-height: 620px; border: 1px solid rgba(221,225,235,.9); border-radius: 24px; box-shadow: var(--shadow); }
  .topbar { padding-top: 12px; }
}

/*
 * WeChat's in-app browser can fail to hand touch scrolling to a nested grid
 * scroller. On phones and tablets, let the document own vertical scrolling
 * and keep the composer above the safe-area inset instead.
 */
@media (max-width: 919px) {
  html, body { height: auto; min-height: 100%; }
  body { overflow-y: auto; }

  .app-shell {
    display: block;
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
    overflow: visible;
  }

  .conversation {
    min-height: calc(100svh - 112px);
    min-height: calc(100dvh - 112px);
    overflow: visible;
    overscroll-behavior: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(142px + env(safe-area-inset-bottom));
  }

  .composer-wrap {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    box-shadow: 0 -8px 22px rgba(24, 32, 51, .06);
  }
}

@media (max-width: 640px) {
  .topbar { min-height: 64px; padding-right: 12px; padding-left: 12px; }
  .conversation, .composer-wrap { padding-right: 14px; padding-left: 14px; }
  .welcome { padding-top: 27px; }
  .assistant-avatar--hero { width: 88px; height: 88px; }
  .assistant-avatar--hero span { font-size: 40px; }
  .quick-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .quick-button { min-height: 68px; display: flex; align-items: center; gap: 10px; }
  .quick-button span { margin: 0; font-size: 20px; }
  .contact-card { grid-template-columns: auto minmax(0, 1fr); }
  .contact-note { display: none; }
  .social-card { padding: 13px; }
  .social-grid { gap: 7px; }
  .social-account { padding: 8px; }
  .social-account__qr { font-size: 9px; }
  .contribute-card { grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 12px; padding: 15px; }
  .contribute-button { grid-column: 1 / -1; justify-content: center; width: 100%; min-height: 42px; }
  .submission-overlay { align-items: end; padding: 10px; }
  .submission-modal { max-height: calc(100dvh - 20px); border-radius: 18px; }
  .submission-modal__header { padding: 20px 18px 15px; }
  .submission-form { padding: 17px 18px 20px; }
  .submission-form__grid { grid-template-columns: 1fr; gap: 0; }
  .message-stack { max-width: 84%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
