:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #15202b;
  --muted: #5d6b7c;
  --line: #e2e7ef;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --accent-soft: #e8f0fe;
  --ok: #1a7f4b;
  --warn: #b7791f;
  --danger: #c0392b;
  --bubble-user: #1f6feb;
  --bubble-ai: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Noto Sans", "Hiragino Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419;
    --card: #1a2029;
    --text: #e8edf3;
    --muted: #94a3b8;
    --line: #2a3340;
    --accent: #4d8ef7;
    --accent-ink: #0b1220;
    --accent-soft: #1b2a44;
    --bubble-user: #2f6fe0;
    --bubble-ai: #1a2029;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419;
  --card: #1a2029;
  --text: #e8edf3;
  --muted: #94a3b8;
  --line: #2a3340;
  --accent: #4d8ef7;
  --accent-ink: #0b1220;
  --accent-soft: #1b2a44;
  --bubble-user: #2f6fe0;
  --bubble-ai: #1a2029;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { max-width: 720px; width: 100%; margin: 0 auto; padding: 0 16px 96px; flex: 1; }

/* 顶部 */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0 6px; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: 0.1px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); display: inline-block; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; font-size: 12px; color: var(--muted); white-space: nowrap; max-width: 150px; overflow: hidden; text-overflow: ellipsis;
}
.chip b { color: var(--text); font-weight: 600; }
.lang { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; font-size: 13px; color: var(--muted); }

/* 卡片 / 通用 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 10px; padding: 11px 16px; border: 1px solid var(--line); background: var(--card); font-weight: 600; min-height: 44px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: default; }
.input, textarea.input, select.input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; background: var(--card); min-height: 44px;
}
textarea.input { min-height: 110px; resize: vertical; }
label.field { display: block; font-size: 13.5px; color: var(--muted); margin-bottom: 12px; }
label.field > .input { margin-top: 6px; }
label.check { display: flex; gap: 10px; align-items: center; font-size: 14px; margin-bottom: 12px; }
.err { color: var(--danger); font-size: 14px; }
.ok { color: var(--ok); }
.hidden { display: none !important; }

/* 底部 Tab */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom);
}
.tabs .inner { display: flex; width: 100%; max-width: 720px; }
.tab {
  flex: 1; background: transparent; border: 0; padding: 10px 4px 8px; color: var(--muted); font-size: 12px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 56px;
}
.tab svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--accent); }
.tab .badge { position: absolute; margin-left: 26px; margin-top: -2px; background: var(--danger); color: #fff; border-radius: 999px; font-size: 10px; padding: 0 5px; line-height: 16px; }

/* FAQ */
.search { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0 10px; }
.search .input { padding-left: 38px; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%237a8797' stroke-width='2' stroke-linecap='round'><circle cx='11' cy='11' r='7'/><path d='m20 20-3.5-3.5'/></svg>"); background-repeat: no-repeat; background-position: 12px center; }
.cats { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.cats::-webkit-scrollbar { display: none; }
.cat { border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 999px; padding: 6px 12px; font-size: 13.5px; white-space: nowrap; min-height: 34px; }
.cat.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.faq-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
.faq-item { border-bottom: 1px solid var(--line); }
.faq-item:last-child { border-bottom: 0; }
.faq-q {
  width: 100%; text-align: left; background: transparent; border: 0; padding: 13px 0; display: flex; justify-content: space-between; gap: 12px; align-items: flex-start;
  font-weight: 600; font-size: 15.5px; line-height: 1.4;
}
.faq-q .chev { flex: none; width: 20px; height: 20px; stroke: var(--muted); fill: none; stroke-width: 2; transition: transform 0.2s; margin-top: 2px; }
.faq-item.open .faq-q .chev { transform: rotate(180deg); }
.faq-a { display: none; padding: 0 0 14px; color: var(--text); font-size: 15px; white-space: pre-wrap; }
.faq-item.open .faq-a { display: block; }
.faq-a .md ol, .faq-a .md ul { padding-left: 20px; margin: 6px 0; }
.faq-foot { display: flex; gap: 8px; margin-top: 10px; }
.faq-foot .btn { padding: 8px 12px; min-height: 36px; font-size: 13.5px; }

/* 聊天 */
.chat { display: flex; flex-direction: column; gap: 12px; padding-bottom: 8px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 86%; padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.5; box-shadow: var(--shadow); word-break: break-word;
}
.msg.user .bubble { background: var(--bubble-user); color: #fff; border-bottom-right-radius: 6px; }
.msg.ai .bubble { background: var(--bubble-ai); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble .md p { margin: 0 0 8px; }
.bubble .md p:last-child { margin-bottom: 0; }
.bubble .md ol, .bubble .md ul { padding-left: 20px; margin: 6px 0; }
.bubble .md code { background: rgba(127, 127, 127, 0.15); padding: 1px 5px; border-radius: 5px; font-size: 0.92em; }
.bubble.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--muted); }
@keyframes blink { to { opacity: 0; } }
.feedback { display: flex; gap: 8px; flex-wrap: wrap; margin: -4px 0 0 4px; }
.feedback .btn { padding: 7px 12px; min-height: 34px; font-size: 13.5px; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.quick .btn { font-weight: 500; font-size: 14px; padding: 9px 12px; min-height: 40px; text-align: left; }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(56px + env(safe-area-inset-bottom)); z-index: 9;
  background: var(--bg); padding: 8px 16px 10px; border-top: 1px solid var(--line);
}
.composer .inner { display: flex; gap: 8px; max-width: 720px; margin: 0 auto; }
.composer textarea { flex: 1; min-height: 44px; max-height: 120px; resize: none; }
.composer .btn { min-width: 64px; }
.has-composer { padding-bottom: 160px; }

/* 工单 */
.ticket-card { display: block; text-decoration: none; color: inherit; }
.ticket-card + .ticket-card { margin-top: 10px; }
.status { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 2px 9px; background: var(--accent-soft); color: var(--accent); }
.status.resolved, .status.closed { background: rgba(26, 127, 75, 0.12); color: var(--ok); }
.status.waiting_user { background: rgba(183, 121, 31, 0.14); color: var(--warn); }
.thread { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.thread .msg .bubble { font-size: 14.5px; }
.thread .who { font-size: 12px; color: var(--muted); margin: 0 6px 3px; }
.thread .msg.user { flex-direction: column; align-items: flex-end; }
.thread .msg.ai { flex-direction: column; align-items: flex-start; }
.ticket-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.ticket-head h2 { font-size: 17px; margin: 0 0 4px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.04em; }
.bigid { font-size: 28px; font-weight: 700; letter-spacing: 0.08em; margin: 6px 0; }
.toast {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 20; opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.toast.show { opacity: 0.95; }

footer { color: var(--muted); font-size: 12.5px; text-align: center; padding: 20px 0 8px; }
footer a { color: var(--muted); }
@media (min-width: 720px) { body { font-size: 16px; } .bubble { max-width: 75%; } }
