:root {
  --brand: #1e6bff;
  --brand-soft: rgba(30, 107, 255, 0.1);
  --bg: #f4f6fa;
  --text: #1f2329;
  --muted: #8a919f;
  --line: #e6e8ee;
  --bubble-bot: #ffffff;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 15px; line-height: 1.6; color: var(--text); background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; }
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 820px; margin: 0 auto; background: var(--bg); }
@media (min-width: 821px) { .app { box-shadow: 0 0 0 1px var(--line); } }

.top { display: flex; align-items: center; gap: 10px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--brand); color: #fff; flex: none; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.22); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 15px; overflow: hidden; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.meta { flex: 1; min-width: 0; }
.name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 12px; opacity: .9; display: flex; align-items: center; gap: 5px; }
.status i { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; display: inline-block; }
.top-btn { border: 1px solid rgba(255,255,255,.6); background: transparent; color: #fff; border-radius: 16px; padding: 4px 12px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.top-btn:hover { background: rgba(255,255,255,.15); }
.top-close { border: 0; background: transparent; color: #fff; font-size: 26px; line-height: 1; width: 34px; height: 34px; cursor: pointer; border-radius: 50%; }
.top-close:hover { background: rgba(255,255,255,.15); }

.msgs { flex: 1; overflow-y: auto; padding: 16px 12px 8px; -webkit-overflow-scrolling: touch; }
.row { display: flex; gap: 8px; margin-bottom: 14px; align-items: flex-start; }
.row.user { flex-direction: row-reverse; }
.row .mini { width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center; flex: none; overflow: hidden; }
.row .mini img { width: 100%; height: 100%; object-fit: cover; }
.bubble { max-width: min(78%, 560px); padding: 9px 13px; border-radius: var(--radius); background: var(--bubble-bot); box-shadow: 0 1px 2px rgba(0,0,0,.05); word-break: break-word; overflow-wrap: anywhere; }
.row.bot .bubble { border-top-left-radius: 4px; }
.row.user .bubble { background: var(--brand); color: #fff; border-top-right-radius: 4px; white-space: pre-wrap; }
.row.sys { justify-content: center; }
.row.sys .bubble { background: transparent; box-shadow: none; color: var(--muted); font-size: 13px; text-align: center; max-width: 90%; }
.row.err .bubble { background: #fff4f4; color: #c0392b; }

.md p { margin: 0 0 6px; }
.md p:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 4px 0 6px; padding-left: 20px; }
.md li { margin: 2px 0; }
.md .md-h { font-weight: 600; margin: 6px 0 4px; }
.md code { background: #f1f3f7; border-radius: 4px; padding: 1px 5px; font-family: Consolas, Menlo, monospace; font-size: 13px; }
.md pre { background: #f1f3f7; border-radius: 8px; padding: 8px 10px; overflow-x: auto; margin: 6px 0; }
.md pre code { background: none; padding: 0; }
.md a { color: var(--brand); word-break: break-all; }

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: #b8bfcc; animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

.extra { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; font-size: 13px; }
.src summary { color: var(--muted); cursor: pointer; user-select: none; }
.src ol { margin: 6px 0 2px; padding-left: 18px; color: #555; }
.src li { margin-bottom: 4px; }
.src li b { display: block; font-weight: 600; color: #333; }
.src li span { color: var(--muted); font-size: 12px; }
.fb { display: flex; gap: 8px; margin-top: 6px; align-items: center; flex-wrap: wrap; }
.fb button { border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 2px 10px; font-size: 12px; color: #666; cursor: pointer; }
.fb button.on { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.fb button.cta { border-color: var(--brand); color: var(--brand); }
.fb .thanks { color: var(--muted); font-size: 12px; }

.suggest { display: flex; gap: 8px; padding: 0 12px 8px; overflow-x: auto; flex: none; scrollbar-width: none; }
.suggest::-webkit-scrollbar { display: none; }
.suggest button { flex: none; border: 1px solid var(--brand); color: var(--brand); background: #fff; border-radius: 16px; padding: 5px 12px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.suggest button:hover { background: var(--brand-soft); }

.composer { display: flex; gap: 8px; padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); flex: none; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 18px; padding: 8px 14px; max-height: 120px; outline: none; background: #f8f9fb; line-height: 1.5; font-size: 15px; overflow-y: hidden; }
.composer textarea:focus { border-color: var(--brand); background: #fff; }
.composer button { border: 0; background: var(--brand); color: #fff; border-radius: 18px; padding: 0 18px; height: 38px; cursor: pointer; font-weight: 500; flex: none; }
.composer button:disabled { opacity: .5; cursor: not-allowed; }
.hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }
.powered { text-align: center; font-size: 11px; color: var(--muted); padding: 2px 0 6px; background: #fff; flex: none; }

.sheet-mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet-mask[hidden] { display: none; }
.sheet { background: #fff; width: 100%; max-width: 480px; border-radius: 16px 16px 0 0; padding: 18px 18px max(18px, env(safe-area-inset-bottom)); }
@media (min-width: 600px) { .sheet-mask { align-items: center; } .sheet { border-radius: 16px; } }
.sheet-title { font-size: 17px; font-weight: 600; }
.sheet-tip { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }
.sheet label { display: block; font-size: 13px; color: #555; margin-bottom: 10px; }
.sheet input, .sheet textarea { display: block; width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; outline: none; font-size: 15px; resize: vertical; }
.sheet input:focus, .sheet textarea:focus { border-color: var(--brand); }
.sheet-err { color: #c0392b; font-size: 13px; margin-bottom: 8px; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; }
.btn-primary, .btn-ghost { border-radius: 8px; padding: 8px 20px; cursor: pointer; font-size: 14px; }
.btn-primary { border: 0; background: var(--brand); color: #fff; }
.btn-primary:disabled { opacity: .6; }
.btn-ghost { border: 1px solid var(--line); background: #fff; }

.fatal { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; color: var(--muted); padding: 24px; text-align: center; }
.fatal[hidden] { display: none; }
