:root {
  color-scheme: light;
  --wechat: #07c160;
  --wechat-dark: #05a950;
  --page: #ededed;
  --ink: #171717;
  --secondary: #7a7f86;
  --line: #d9dadd;
  --assistant: #ffffff;
  --user: #95ec69;
  --card: rgba(255, 255, 255, 0.96);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: #dfe3e6; color: var(--ink); }

body { min-height: 100dvh; }

button, textarea { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 540px);
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 80% 8%, rgba(7, 193, 96, 0.08), transparent 28%),
    var(--page);
  box-shadow: 0 0 42px rgba(35, 45, 55, 0.13);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: calc(64px + env(safe-area-inset-top));
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  display: flex;
  align-items: center;
  gap: 11px;
  background: rgba(247, 247, 247, 0.92);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(18px);
}

.brand-mark, .avatar {
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #10cf70, #059a4b);
  font-weight: 800;
  box-shadow: inset 0 1px rgba(255,255,255,.25);
}

.brand-mark { width: 40px; height: 40px; border-radius: 12px; font-size: 20px; }
.avatar { width: 34px; height: 34px; border-radius: 8px; flex: 0 0 auto; font-size: 12px; }

.title-block { min-width: 0; flex: 1; }
.title-block h1 { margin: 0; font-size: 17px; letter-spacing: .02em; }
.title-block p { margin: 3px 0 0; color: var(--secondary); font-size: 11px; }
.status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: #b2b7bc; }
.status-dot.ok { background: var(--wechat); box-shadow: 0 0 0 3px rgba(7,193,96,.12); }
.status-dot.warn { background: #eaa326; }

.icon-button { width: 38px; height: 38px; border: 0; border-radius: 10px; background: transparent; font-size: 23px; letter-spacing: 2px; }
.icon-button:active { background: #e5e5e5; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 170px;
  scroll-behavior: smooth;
}

.message { display: flex; gap: 9px; margin: 0 0 18px; align-items: flex-start; animation: rise .2s ease-out; }
.message.user { flex-direction: row-reverse; }
.message.user .avatar { background: linear-gradient(145deg, #828a91, #596169); }

.bubble {
  position: relative;
  max-width: calc(100% - 64px);
  padding: 10px 12px;
  border-radius: 5px;
  background: var(--assistant);
  line-height: 1.62;
  font-size: 15px;
  box-shadow: 0 1px 1px rgba(0,0,0,.035);
  overflow-wrap: anywhere;
}
.bubble > div:first-child { white-space: pre-wrap; }

.message.assistant .bubble::before, .message.user .bubble::before {
  content: ""; position: absolute; top: 13px; border: 6px solid transparent;
}
.message.assistant .bubble::before { left: -11px; border-right-color: var(--assistant); }
.message.user .bubble { background: var(--user); }
.message.user .bubble::before { right: -11px; border-left-color: var(--user); }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.muted { color: #6e747a; font-size: 12px; }
.source-row { margin-top: 9px; padding-top: 8px; border-top: 1px solid #ececec; color: #858a90; font-size: 11px; }

.speak-button {
  margin-top: 9px; padding: 5px 9px; border: 1px solid #e0e2e4; border-radius: 6px; color: #62676d; background: #f8f9f9; font-size: 12px;
}

.analysis-card {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid #e6e9e8;
  border-radius: 10px;
  background: linear-gradient(160deg, #fbfffc, #f7faf8);
}
.analysis-card h3 { margin: 0 0 10px; font-size: 14px; }
.probability-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.probability-box { padding: 8px 5px; border-radius: 8px; background: #fff; text-align: center; border: 1px solid #eceded; }
.probability-box strong { display: block; margin-top: 3px; color: #087e42; font-size: 16px; }
.probability-box span { color: #777d82; font-size: 11px; }
.quality-row { display: flex; justify-content: space-between; margin-top: 9px; color: #747a7f; font-size: 11px; }

.quick-panel { margin: 4px 43px 20px; }
.quick-title { margin: 0 0 8px; color: #7a8085; font-size: 12px; }
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quick-chip { padding: 10px 8px; border: 1px solid #dfe3e1; border-radius: 9px; background: rgba(255,255,255,.75); color: #303438; font-size: 13px; text-align: left; }
.quick-chip:active { background: #e4f5ea; }

.composer-wrap {
  position: fixed;
  bottom: 0;
  z-index: 20;
  width: min(100%, 540px);
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(247,247,247,.96);
  border-top: 1px solid rgba(0,0,0,.09);
  backdrop-filter: blur(18px);
}
.responsible-note { padding: 6px 14px 0; color: #999ea2; font-size: 10px; text-align: center; }
.composer { min-height: 61px; padding: 8px 10px 10px; display: flex; align-items: flex-end; gap: 8px; }
.round-button { width: 38px; height: 38px; flex: 0 0 auto; border: 0; background: transparent; padding: 7px; }
.round-button svg { width: 100%; height: 100%; fill: #303438; }
#message-input { flex: 1; min-height: 38px; max-height: 110px; resize: none; padding: 8px 10px; border: 1px solid #dedede; border-radius: 7px; outline: none; background: #fff; line-height: 20px; }
#message-input:focus { border-color: #b8d9c7; }
.send-button { height: 38px; padding: 0 14px; border: 0; border-radius: 7px; background: var(--wechat); color: #fff; }
.send-button:disabled { background: #d3d6d4; color: #f3f3f3; }
.hold-button {
  flex: 1;
  height: 38px;
  border: 1px solid #d4d7d5;
  border-radius: 7px;
  background: #fff;
  color: #25282a;
  font-weight: 600;
  /* 微信WebView会把长按识别为滚动、选词或系统菜单，必须由录音按钮独占手势。 */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.hold-button.recording { background: #dfe2e0; }

.recording-bar { position: fixed; left: 50%; bottom: 83px; z-index: 30; transform: translateX(-50%); width: min(88%, 420px); padding: 13px 14px; border-radius: 12px; background: rgba(31,34,36,.9); color: #fff; text-align: center; font-size: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.22); }
.recording-bar span { display: block; }
.recording-pulse { width: 12px; height: 12px; margin: 0 auto 8px; border-radius: 50%; background: #ff4d4f; animation: pulse 1s infinite; }
.recording-bar span:last-child { margin-top: 5px; color: #c5c8ca; font-size: 10px; }

.typing { display: flex; gap: 4px; padding: 7px 2px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: #aeb4b8; animation: bounce 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }

dialog { width: min(88%, 420px); padding: 18px; border: 0; border-radius: 13px; box-shadow: 0 24px 70px rgba(0,0,0,.25); line-height: 1.7; }
dialog::backdrop { background: rgba(0,0,0,.38); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head button { border: 0; background: transparent; font-size: 25px; }
dialog p { color: #5f656a; font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 14px; }
.clear-history-button { padding: 8px 12px; border: 1px solid #e2a3a3; border-radius: 7px; background: #fff; color: #b3261e; font-size: 13px; }

.toast { position: fixed; left: 50%; top: 42%; z-index: 50; transform: translate(-50%, -50%); max-width: 80%; padding: 11px 15px; border-radius: 8px; background: rgba(20,22,24,.88); color: #fff; font-size: 13px; text-align: center; }
.hidden { display: none !important; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes pulse { 50% { transform: scale(1.35); opacity: .55; } }
@keyframes bounce { 50% { transform: translateY(-4px); } }

@media (min-width: 541px) {
  body { padding: 18px 0; }
  .app-shell { min-height: calc(100dvh - 36px); border-radius: 18px; overflow: hidden; }
  .composer-wrap { bottom: 18px; border-radius: 0 0 18px 18px; }
}
