:root {
  --green: #1f6f5c; --green-d: #17584a; --bg: #f1f3f2; --card: #fff; --line: #e3e7e5; --text: #1b2421; --muted: #7b8782;
  --mine: #d6f1e3; --bot: #fff; --other: #e8eefb;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 16px; overscroll-behavior: none; }
#app { height: 100%; height: 100dvh; max-width: 760px; margin: 0 auto; position: relative; background: var(--bg); }
.hidden { display: none !important; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--green); color: #fff; flex: none; }
.bar h1 { margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grow { flex: 1; min-width: 0; } .spacer { flex: 1; }
.btn { font: inherit; border: 0; border-radius: 10px; padding: 10px 14px; background: #e6ebe9; color: var(--text); cursor: pointer; }
.btn.primary { background: var(--green); color: #fff; }
.bar .btn.primary { background: #fff; color: var(--green); font-weight: 600; }
.btn.ghost { background: transparent; }
.bar .btn.ghost { color: #fff; background: rgba(255,255,255,.18); }
.btn.small { padding: 7px 11px; font-size: 14px; }
.btn.icon { padding: 6px 10px; font-size: 22px; background: transparent; color: inherit; line-height: 1; }
.bar .btn.icon { color: #fff; font-size: 28px; }
.btn:active { opacity: .75; }

/* login */
#view-login { align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-logo { width: 84px; height: 84px; border-radius: 20px; margin: 0 auto; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
input, textarea { font: inherit; }
.login-card input, .dialog-card input { padding: 13px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; width: 100%; font-size: 16px; }
.err { color: #c0392b; min-height: 1.2em; margin: 0; font-size: 14px; }

/* list */
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; background: var(--card); }
.conv-list li { display: flex; gap: 12px; align-items: center; padding: 13px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv-list li:active { background: #f3f6f5; }
.avatar { width: 44px; height: 44px; border-radius: 12px; background: var(--green); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; flex: none; font-size: 18px; }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; }
.conv-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { color: var(--muted); font-size: 12px; flex: none; }
.conv-prev { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 3px; }
.conv-prev .typing-mini { color: var(--green); }
.badge { background: #e5484d; color: #fff; border-radius: 10px; min-width: 20px; height: 20px; padding: 0 6px; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; margin-left: 6px; }
.empty { color: var(--muted); text-align: center; padding: 40px 28px; line-height: 1.6; }

/* chat */
.messages { flex: 1; overflow-y: auto; padding: 12px 10px 6px; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }
.daysep { align-self: center; font-size: 12px; color: var(--muted); background: rgba(0,0,0,.05); padding: 2px 10px; border-radius: 10px; }
.msg { max-width: 82%; display: flex; flex-direction: column; gap: 3px; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }
.who { font-size: 12px; color: var(--muted); padding: 0 4px; }
.who b { font-weight: 600; }
.bubble { padding: 9px 12px; border-radius: 14px; background: var(--bot); box-shadow: 0 1px 1px rgba(0,0,0,.06); word-break: break-word; overflow-wrap: anywhere; line-height: 1.45; max-width: 100%; }
.msg.mine .bubble { background: var(--mine); border-top-right-radius: 4px; }
.msg.theirs .bubble { border-top-left-radius: 4px; }
.msg.from-user.theirs .bubble { background: var(--other); }
.msg.from-muse .bubble { background: #f3e8ff; }
.msg.from-muse .who b { color: #6b3fa0; }
.bubble.textless { padding: 4px; }
.bubble .text { white-space: pre-wrap; }
.bubble a { color: #1a5fb4; }
.bubble .text + .att, .att + .att { margin-top: 6px; }
.att img.thumb { display: block; max-width: 100%; max-height: 260px; border-radius: 10px; cursor: zoom-in; background: #eee; }
.att video { display: block; max-width: 100%; max-height: 300px; border-radius: 10px; background: #000; }
.filechip { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: rgba(0,0,0,.05); border-radius: 10px; color: inherit !important; text-decoration: none; min-width: 190px; }
.filechip .ic { font-size: 26px; }
.filechip .fn { font-size: 14px; word-break: break-all; }
.filechip .fs { font-size: 12px; color: var(--muted); }
.time { font-size: 11px; color: var(--muted); padding: 0 4px; }
.typing { align-self: flex-start; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; padding: 4px 6px; }
.dots { display: inline-flex; gap: 3px; background: #fff; padding: 9px 11px; border-radius: 14px; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: #9aa5a0; animation: bl 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes bl { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.more { align-self: center; font-size: 13px; color: var(--green); background: none; border: 0; padding: 4px 10px; }

.pending { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 10px 0; background: var(--card); border-top: 1px solid var(--line); }
.pchip { position: relative; background: #eef2f0; border-radius: 10px; padding: 6px 28px 6px 8px; font-size: 13px; display: flex; align-items: center; gap: 6px; max-width: 100%; }
.pchip img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; }
.pchip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.pchip button { position: absolute; right: 2px; top: 2px; border: 0; background: none; font-size: 18px; color: #666; padding: 2px 6px; }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); flex: none; flex-wrap: wrap; }
.composer .tools { display: flex; width: 100%; gap: 2px; }
.composer .tools .btn { font-size: 22px; padding: 4px 12px; }
.composer textarea { flex: 1; min-width: 0; resize: none; border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; max-height: 120px; background: #fff; font-size: 16px; line-height: 1.4; }
.composer .send { padding: 10px 18px; flex: none; }
.composer .send[disabled] { opacity: .5; }
.progress { height: 3px; background: var(--green); width: 0; transition: width .2s; position: absolute; left: 0; top: 0; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 50; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.dialog { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 24px; }
.dialog-card { background: #fff; border-radius: 16px; padding: 18px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.dialog-card h2 { margin: 0; font-size: 17px; }
.dialog-btns { display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: rgba(30,30,30,.9); color: #fff; padding: 9px 16px; border-radius: 20px; z-index: 70; font-size: 14px; max-width: 86%; text-align: center; }

@media (min-width: 900px) {
  body { background: #dfe5e2; }
  #app { box-shadow: 0 0 30px rgba(0,0,0,.12); }
}

.bar a.btn { text-decoration: none; display: inline-block; }
.composer .tools { align-items: center; }
.esc { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 4px; padding-right: 6px; user-select: none; }
.esc input { width: 17px; height: 17px; accent-color: var(--green); }
.tag-main { font-size: 11px; background: #fde8c8; color: #8a5a00; border-radius: 6px; padding: 0 5px; margin-left: 4px; }
.tag-esc { font-size: 11px; color: var(--green); }
