:root {
  --accent: #5b3cc4;
  --text: #222;
  --muted: #8a8a92;
  --line: #e6e6ea;
  --bg: #ffffff;
  --bg-soft: #f4f4f6;
  --bot-bubble: #e1e3fb;
  --user-bubble: #e3f0fa;
  --chip: #f3f3f5;
  --sec-info: #eef2f8;
  --sec-core: #e9ebf0;
  --sec-insight: #f7eef5;
  --sec-tips: #e1e3fb;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #ececef;
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 16px;
  line-height: 1.6;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

#app {
  position: relative;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
}
.view { display: flex; flex-direction: column; height: 100%; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* 顶栏 */
.topbar {
  display: flex; align-items: center; gap: 8px;
  height: 64px; padding: 0 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.topbar .right { margin-left: auto; }
.brand { font-weight: 600; font-size: 24px; letter-spacing: 2px; margin: 0; }
.tagline { margin: 0 0 8px; }
.plain-title { font-size: 24px; font-weight: normal; margin: 0; }
.brand-en { font-weight: 600; font-size: 20px; text-align: center; }
.icon-btn {
  width: 40px; height: 40px; padding: 8px;
  border: 0; background: none; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--bg-soft); }
.icon-btn svg, .send-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* 登录 */
.login-box { margin: auto; width: 100%; padding: 32px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.login-box input {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; outline: none;
}
.login-box input:focus { border-color: var(--accent); }
.primary { width: 100%; padding: 12px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-size: 16px; }
.err { color: #c0392b; min-height: 1.5em; margin: 0; font-size: 14px; }
.avatar-lg { width: 180px; height: 180px; display: block; margin: 0 auto; }

/* 咨询 */
#chat-scroll { padding: 16px 16px 8px; }
#welcome { display: flex; flex-direction: column; gap: 12px; padding: 8px 12px 16px; }
#welcome .avatar-lg { margin-top: 8px; }
.welcome-text { background: var(--bot-bubble); border-radius: 10px; padding: 14px 16px; margin-top: 12px; }
.chip { text-align: left; border: 0; border-radius: 22px; background: var(--chip); padding: 10px 16px; }
.chip:active { background: var(--line); }

.msg { display: flex; gap: 10px; margin: 10px 0; align-items: flex-start; }
.msg.user { flex-direction: row-reverse; }
.msg .avatar { width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; }
.msg .bubble { max-width: 76%; padding: 10px 14px; border-radius: 10px; white-space: pre-wrap; word-break: break-word; }
.msg.bot .bubble { background: var(--bot-bubble); }
.msg.user .bubble { background: var(--user-bubble); }
/* 裸模型组：整条回复一个气泡，渲染 Markdown */
.msg .bubble.md { white-space: normal; }
.bubble.md > :first-child { margin-top: 0; }
.bubble.md > :last-child { margin-bottom: 0; }
.bubble.md p { margin: 0 0 8px; }
.bubble.md h4 { margin: 12px 0 6px; font-size: 1em; }
.bubble.md ul, .bubble.md ol { margin: 0 0 8px; padding-left: 1.5em; }
.bubble.md li { margin: 2px 0; }
.bubble.md blockquote { margin: 0 0 8px; padding-left: 10px; border-left: 3px solid rgba(0, 0, 0, .18); }
.bubble.md hr { border: 0; border-top: 1px solid rgba(0, 0, 0, .12); margin: 10px 0; }
.bubble.md code { font-family: Consolas, Menlo, monospace; font-size: .92em; background: rgba(0, 0, 0, .06); border-radius: 4px; padding: 0 4px; }
.note { text-align: center; color: var(--muted); font-size: 13px; margin: 8px 0; }
.interrupted-tag { color: var(--muted); font-size: 12px; margin: -4px 0 8px 50px; }
.typing span { display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.composer textarea {
  flex: 1; resize: none; max-height: 132px;
  padding: 9px 12px; font: inherit; line-height: 1.4;
  border: 1px solid var(--line); border-radius: 20px; outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
#btn-mic.listening { color: #fff; background: var(--accent); animation: pulse 1.2s infinite; }
#btn-mic.busy { opacity: .45; }  /* 录音已上传，正在识别 */
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(91, 60, 196, .2); } }
.send-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: var(--accent); color: #fff; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.send-btn .i-stop, .send-btn.streaming .i-send { display: none; }
.send-btn.streaming .i-stop { display: block; }

/* 菜单 */
.drawer { position: absolute; inset: 0; background: rgba(0, 0, 0, .35); z-index: 10; }
.drawer-panel { width: 70%; height: 100%; background: var(--bg); padding: 24px 0; display: flex; flex-direction: column; }
.drawer-user { padding: 0 20px 16px; color: var(--muted); font-size: 14px; border-bottom: 1px solid var(--line); }
.drawer-panel button { text-align: left; border: 0; background: none; padding: 14px 20px; font-size: 17px; }
.drawer-panel button:active { background: var(--bg-soft); }

/* 日历 */
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; background: var(--bg-soft); padding: 12px 0; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.month-nav { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px; color: var(--muted); flex-shrink: 0; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); row-gap: 6px; padding: 0 8px 12px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.day {
  position: relative; width: 44px; height: 44px; margin: 0 auto;
  border: 0; border-radius: 50%; background: none; font-size: 18px;
}
.day.other { visibility: hidden; }
.day.empty { color: #c4c4ca; }
.day.has::after { content: ""; position: absolute; left: 50%; bottom: 4px; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: #666; }
.day.selected { background: var(--accent); color: #fff; }
.day.selected::after { background: #fff; }
.day-title { background: var(--bg-soft); padding: 12px 16px 0; color: var(--muted); font-size: 14px; flex-shrink: 0; }
.day-sessions { background: var(--bg-soft); padding: 12px 16px 16px; }
.session-card { display: flex; align-items: stretch; width: 100%; margin-bottom: 14px; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); overflow: hidden; text-align: left; }
.session-card .time { background: var(--accent); color: #fff; padding: 14px 12px; min-width: 72px; text-align: center; }
.session-card .title { flex: 1; padding: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-card .open-tag { color: var(--accent); font-size: 13px; margin-left: 6px; }
.session-card .chev { padding: 14px 12px; color: var(--muted); }
.empty-hint { color: var(--muted); text-align: center; padding: 24px 0; }

/* 总结 */
.sum-sec { padding: 18px 18px 20px; }
.sum-sec h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; font-size: 19px; }
.sum-sec h2 svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sum-sec.info { background: var(--sec-info); }
.sum-sec.core { background: var(--sec-core); }
.sum-sec.insight { background: var(--sec-insight); }
.sum-sec.tips { background: var(--sec-tips); }
.sum-sec ol { margin: 0; padding-left: 1.4em; }
.sum-sec li { margin: 6px 0; }
.sum-sec li::marker { color: var(--accent); font-weight: 600; }
.kv { display: grid; grid-template-columns: 56px 1fr; row-gap: 4px; }
.kv .k { color: var(--muted); }
.sum-state { padding: 32px 18px; text-align: center; color: var(--muted); }
.sum-state button { margin-top: 12px; padding: 8px 20px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; }
.crisis-banner { background: #fdecea; color: #a93226; padding: 12px 18px; font-size: 14px; }
#dialogue-body { padding: 16px; }

/* 提示 */
.toast {
  position: absolute; left: 50%; bottom: 90px; transform: translateX(-50%);
  max-width: 86%; padding: 10px 16px; border-radius: 8px;
  background: rgba(30, 30, 36, .88); color: #fff; font-size: 14px; z-index: 20;
}
