:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #1d4ed8;
  --accent-soft: #dbe5ff;
  --talk: #dc2626;
  --rx: #059669;
  --mine: #e8efff;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --panel: #111827; --ink: #e5e7eb; --muted: #94a3b8; --line: #1f2937;
    --accent: #6d8dff; --accent-soft: #1e2a4d; --mine: #1b2540;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-tap-highlight-color: transparent; }
#app { height: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.pad { padding: 16px; }
.link { color: var(--accent); text-decoration: none; display: inline-block; margin-top: 8px; }
.view { height: 100%; }

/* login */
#view-login, #view-start { display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px 22px; }
.login-card.center { text-align: center; }
.brand { font-size: 26px; font-weight: 700; display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.login-card.center .brand { justify-content: center; }
.brand-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--talk); box-shadow: 0 0 0 5px rgba(220,38,38,.18); }
.field { display: block; margin: 16px 0 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input { width: 100%; font: inherit; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); outline: none; }
input:focus { border-color: var(--accent); }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 10px 14px; border-radius: 10px; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; margin-top: 20px; padding: 13px; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.msg { min-height: 20px; color: var(--talk); font-size: 13px; margin: 10px 0 0; }
.msg.ok { color: var(--rx); }

/* main */
#view-main { display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me-name { font-weight: 600; }
.me-code { font-size: 13px; color: var(--muted); }
.me-code b { color: var(--ink); letter-spacing: 1px; }
.chip { font: inherit; font-size: 12px; border: 1px solid var(--line); background: transparent; color: var(--accent);
  border-radius: 999px; padding: 1px 8px; margin-left: 4px; cursor: pointer; }
.icon-btn { font: inherit; font-size: 22px; background: none; border: none; color: var(--ink); cursor: pointer; padding: 4px 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; background: #94a3b8; }
.dot.on { background: #10b981; }
.dot.off { background: #94a3b8; }
.dot.wait { background: #f59e0b; }

.layout { flex: 1; display: flex; min-height: 0; }
.pane { background: var(--panel); }
#pane-list { width: 320px; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.pane-actions { display: flex; gap: 6px; padding: 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.contact-list { overflow-y: auto; flex: 1; }
.feedback-link { display: block; width: 100%; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--muted);
  padding: 12px; font: inherit; font-size: 14px; cursor: pointer; text-align: center; }
.feedback-link:hover { color: var(--ink); }
.fb-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent, #ff5b1f); margin-left: 6px; vertical-align: middle; }
.fb-form textarea { width: 100%; min-height: 110px; resize: vertical; font: inherit; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); box-sizing: border-box; }
.fb-form textarea:focus { border-color: var(--accent); outline: none; }
.fb-check { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; cursor: pointer; }
.fb-check input { width: 18px; height: 18px; padding: 0; flex: none; margin: 1px 0 0; accent-color: var(--accent); }
.fb-form .row { margin-top: 8px; }
.fb-thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.fb-thumbs img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; }
.fb-item { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-top: 8px; }
.fb-item.unread { border-color: var(--accent, #ff5b1f); }
.fb-msg { margin-top: 6px; padding: 7px 10px; border-radius: 10px; white-space: pre-wrap; font-size: 14px; }
.fb-msg.admin { background: var(--accent, #ff5b1f); color: #fff; margin-right: 30px; }
.fb-msg.user { background: var(--bg); margin-left: 30px; }
.fb-follow { display: flex; gap: 6px; margin-top: 8px; }
.contact { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--line); }
.contact:hover { background: var(--bg); }
.contact.active { background: var(--accent-soft); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; position: relative; }
.avatar.group, .avatar.agent { border-radius: 12px; }
.avatar.agent { background: #6d5dfc; color: #fff; }
/* 头像: the picture fills the shape (round for people and the assistant, rounded square for groups and agents) */
.avatar img.av-pic { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }
.avatar.msg { width: 36px; height: 36px; font-size: 14px; cursor: zoom-in; margin-top: 2px; }
.avatar.big-ish { width: 48px; height: 48px; cursor: zoom-in; }
.avatar.big { width: min(70vw, 70vh); height: min(70vw, 70vh); font-size: min(30vw, 30vh); }
.av-set { display: flex; align-items: center; gap: 10px; }
.msg-row { display: flex; align-items: flex-start; gap: 8px; align-self: flex-start; max-width: 88%; }
.msg-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-row > .item { max-width: none; align-self: auto; min-width: 0; }
.avatar .dot { position: absolute; right: -2px; bottom: -2px; border: 2px solid var(--panel); width: 12px; height: 12px; }
.contact-main { flex: 1; min-width: 0; }
.contact-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-sub { font-size: 12px; color: var(--muted); }
.badge { background: var(--talk); color: #fff; border-radius: 999px; font-size: 12px; padding: 0 7px; min-width: 20px; text-align: center; }
.speaking { color: var(--rx); font-weight: 600; }

.conv { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.conv-head { display: flex; align-items: center; gap: 6px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.conv-title { font-weight: 700; }
.back { display: none; }
.history { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.item { max-width: 78%; align-self: flex-start; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 12px; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.item.mine { align-self: flex-end; background: var(--mine); }
.item .play { width: 30px; height: 30px; border-radius: 50%; border: none; background: var(--accent); color: #fff; font-size: 12px; flex: none; }
.item.playing .play { background: var(--rx); }
.item .meta { font-size: 12px; color: var(--muted); }
.item .who { font-size: 13px; font-weight: 600; }
.item > div { min-width: 0; }
.item .said { font-size: 15px; line-height: 1.4; margin-top: 4px; white-space: pre-wrap; word-break: break-word; user-select: text; -webkit-user-select: text; cursor: text; }
.item.unheard .who::after { content: " ●"; color: var(--talk); }
.item.live { border-color: var(--rx); }

.ptt-wrap { padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: var(--panel); border-top: 1px solid var(--line); }
.ptt-status { font-size: 14px; color: var(--muted); min-height: 21px; text-align: center; }
.ptt-status.talk { color: var(--talk); font-weight: 600; }
.ptt-status.rx { color: var(--rx); font-weight: 600; }
/* 收到确认 */
.ack-toggle { font: inherit; font-size: 14px; font-weight: 600; color: var(--muted); background: transparent; border: 1px solid var(--line);
  border-radius: 20px; padding: 6px 14px; margin: 2px 0 8px; cursor: pointer; }
.ack-toggle.on { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }
.ack-line { font-size: 12px; color: var(--muted); margin-top: 4px; }
.ack-line.done { color: var(--rx); }
.ack-btn { margin-top: 6px; }
.ptt { position: relative; width: 132px; height: 132px; border-radius: 50%; border: none; background: var(--accent); color: #fff;
  font: 600 17px/1 inherit; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none;
  box-shadow: 0 8px 24px rgba(29,78,216,.25); transition: transform .08s, background .15s; }
.ptt:disabled { background: #94a3b8; box-shadow: none; cursor: default; }
.ptt.down { transform: scale(.94); background: var(--talk); box-shadow: 0 8px 28px rgba(220,38,38,.35); }
.ptt.busy { background: #f59e0b; }
.ptt-ring { position: absolute; inset: -8px; border-radius: 50%; border: 3px solid transparent; }
.ptt.down .ptt-ring { border-color: rgba(220,38,38,.35); animation: pulse 1s infinite; }
@keyframes pulse { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(1.15); opacity: 0; } }
.level { width: 160px; height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
#level-bar { height: 100%; width: 0; background: var(--talk); transition: width .05s; }

/* modal & toast */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal-card { width: 100%; max-width: 380px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; background: var(--panel); border-radius: var(--radius); padding: 20px; }
.modal-card h3 { margin: 0 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.setting { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.setting:last-child { border-bottom: none; }
.toast { position: fixed; left: 50%; bottom: 210px; transform: translateX(-50%); background: rgba(15,23,42,.92); color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20; max-width: 86%; text-align: center; }
.big-code { font-size: 28px; font-weight: 700; letter-spacing: 3px; text-align: center; margin: 10px 0; }

@media (max-width: 720px) {
  #pane-list { width: 100%; border-right: none; }
  .layout.in-conv #pane-list { display: none; }
  .layout:not(.in-conv) #pane-conv { display: none; }
  .back { display: inline-block; }
}

/* language picker */
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.brand-row .brand { white-space: nowrap; }
.lang-pick { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.lang-pick select { width: auto; max-width: 160px; padding: 4px 6px; font-size: 13px; border-radius: 8px; }
[dir="rtl"] .ptt-status, [dir="rtl"] .conv-head { text-align: right; }

/* consent, danger buttons, conversation menu */
.agree { display: flex; gap: 8px; align-items: flex-start; margin-top: 16px; color: var(--muted); line-height: 1.5; cursor: pointer; }
.agree input { width: auto; margin: 3px 0 0; flex: none; }
.shake { animation: shake .4s; }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.btn.danger { color: #fff; background: #dc2626; border-color: #dc2626; }
.conv-head-main { flex: 1; min-width: 0; }
.agree .link { margin-top: 0; }
.who .remark { padding: 0 6px; font-size: 11px; margin-left: 4px; }
.menu .btn.block { margin-top: 8px; }
label.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 15px; cursor: pointer; }
label.check input { width: auto; margin: 0; }
.item.recalled { display: block; align-self: center; max-width: none; text-align: center; color: var(--muted); font-size: 13px; padding: 4px 0; background: none; border: 0; box-shadow: none; cursor: default; }

.member-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 2px; border-bottom: 1px solid var(--line); }
.member-row:last-child { border-bottom: 0; }
#members-list { max-height: 60vh; overflow: auto; }
.menu-list { display: grid; gap: 10px; }
.menu-list .btn { width: 100%; }
#members-list .member-name { min-width: 0; }
#members-list .member-name[data-friend="0"][data-me="0"] { cursor: pointer; }
.member-acts { display: flex; align-items: center; gap: 6px; flex-shrink: 0; white-space: nowrap; }

/* assistant & text messages */
.avatar.assistant { background: linear-gradient(135deg, #6d5dfc, #22b8cf); color: #fff; }
.ai-tag { display: inline-block; font-size: 10px; font-weight: 700; line-height: 1; padding: 2px 5px; margin-left: 4px; border-radius: 6px;
  background: linear-gradient(135deg, #6d5dfc, #22b8cf); color: #fff; vertical-align: middle; letter-spacing: .02em; white-space: nowrap; }
.item.text { cursor: default; }
.item.text .said { margin: 2px 0 4px; }
.item.bot { border-color: #b9b2ff; }
.item.typing .said { color: var(--muted); }

/* teams */
.team-tag { display: inline-block; font-size: 10px; font-weight: 700; line-height: 1; padding: 2px 5px; margin-left: 4px; border-radius: 6px;
  background: #0f766e; color: #fff; vertical-align: middle; }
.role-tag { display: inline-block; font-size: 11px; line-height: 1.2; padding: 1px 6px; border-radius: 6px; vertical-align: middle;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.role-tag.owner { background: #fef3c7; color: #92400e; }
.role-tag.member { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.team-invite { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 8px 0 4px; }
.invite-url { font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; margin: 6px 0 8px; user-select: all; }
.team-h { margin: 14px 0 2px; font-size: 14px; }
.dept-tag { display: inline-block; font-size: 11px; line-height: 1.2; padding: 1px 6px; border-radius: 6px; vertical-align: middle;
  background: #ecfeff; color: #0e7490; border: 1px solid #a5f3fc; white-space: nowrap; }
.chip.danger { color: var(--talk); }
#team-members .member-acts { flex-wrap: wrap; justify-content: flex-end; white-space: normal; }
.assign-form { display: grid; gap: 6px; margin: 4px 0 10px; padding: 8px; border: 1px dashed var(--line); border-radius: 10px; }
.assign-row { display: flex; flex-wrap: wrap; gap: 6px; }
.assign-row > * { min-width: 0; }
.assign-row input { width: auto; }
.assign-row select { flex: 1 1 120px; }
.assign-row input[type="datetime-local"] { flex: 1 1 170px; }
.assign-row #ta-text { flex: 1 1 160px; }
.assign-row .btn { flex: none; }
.assign-row select { font: inherit; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.assign-row select:focus { border-color: var(--accent); outline: none; }
.task-row { padding: 7px 2px; border-bottom: 1px solid var(--line); }
.task-row:last-child { border-bottom: 0; }
.task-text { font-size: 14px; }
.task-note { color: var(--ink); opacity: .8; margin-top: 2px; }
.task-sub { margin-top: 10px; }
.task-st { font-weight: 600; }
.task-st.sent { color: #b45309; }
.task-st.confirmed { color: var(--accent); }
.task-st.done { color: var(--rx); }
.task-st.declined, .late { color: var(--talk); }
.task-st.cancelled { color: var(--muted); }
.dots { display: inline-flex; gap: 3px; vertical-align: middle; margin-right: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .3; animation: dot 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes dot { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: .6; } }
.item.reading { border-color: var(--rx); box-shadow: 0 0 0 2px color-mix(in srgb, var(--rx) 25%, transparent); }
.item .read { padding: 0 6px; font-size: 11px; }
.text-form { display: flex; gap: 8px; padding: 8px 16px 0; }
.text-form input { flex: 1; min-width: 0; }
.text-form.hidden { display: none; }

/* pictures */
.pic-btn { padding: 0 10px; font-size: 18px; line-height: 1; }
.item.image .img-open { display: block; padding: 0; margin: 6px 0 2px; border: 1px solid var(--line, #e2e5ea); border-radius: 10px; overflow: hidden; background: var(--line); cursor: zoom-in; max-width: 100%; }
.item.image .img-open img { display: block; width: 100%; height: 100%; object-fit: cover; }
.item.image .img-open.broken { cursor: default; }
.item.image .pic-gone { padding: 18px 12px; margin: 6px 0 2px; border: 1px dashed var(--line, #e2e5ea); border-radius: 10px; }
.pic-view { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .86); cursor: zoom-out; padding: 16px; }
.pic-view img { max-width: 100%; max-height: 100%; object-fit: contain; }
.pic-view p { color: #ddd; }

/* agents and cards */
.agent-tag { display: inline-block; font-size: 11px; padding: 0 6px; margin-left: 4px; border-radius: 8px; border: 1px solid #6D5DFC; color: #6D5DFC; vertical-align: 1px; }
.item.agent > div { border-left: 3px solid #6D5DFC; padding-left: 10px; }
.item.card .card-box { margin: 6px 0 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); min-width: 220px; max-width: 360px; }
.card-title { font-weight: 600; margin-bottom: 6px; }
.card-line { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; padding: 2px 0; }
.card-line span { color: var(--muted); }
.card-note { font-size: 13px; margin-top: 6px; }
.card-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.card-state { font-size: 13px; margin-top: 8px; }
.card-confirm-text { margin-top: 8px; padding: 8px 10px; border: 1px solid var(--ink, currentColor); border-radius: 8px; font-weight: 600; font-size: 14px; }
.card-state.err { color: #c0392b; }
#card-reply { width: 100%; font: inherit; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
.agent-row { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.agent-row .setting { margin: 4px 0; }
.card-link { text-decoration: none; }
.meta .routed { color: #6D5DFC; }
