:root {
  --brand: #2f6bff;
  --ink: #172038;
  --text: #4b5772;
  --muted: #8b96ab;
  --line: #e8ecf4;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: #f4f6fb;
  font-size: 14px;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
.hidden { display: none !important; }

.m-login {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background:
    radial-gradient(600px 300px at 20% 10%, rgba(47, 107, 255, .16), transparent 62%),
    #f7f9fe;
}
.m-login-card { width: 100%; max-width: 360px; background: #fff; border-radius: 18px; padding: 26px 22px; box-shadow: 0 18px 46px rgba(24, 39, 75, .12); }
.m-logo { font-weight: 800; color: var(--brand); display: flex; gap: 7px; align-items: center; }
.m-logo span { color: var(--ink); }
.m-login h1 { font-size: 20px; color: var(--ink); margin: 20px 0 16px; }
.m-login form { display: flex; flex-direction: column; gap: 12px; }
.m-login input { border: 1px solid var(--line); border-radius: 10px; padding: 12px; outline: none; background: #fbfcff; }
.m-login input:focus { border-color: var(--brand); background: #fff; }
.m-login button { height: 44px; border-radius: 10px; background: var(--brand); color: #fff; font-weight: 600; }
.m-error { color: #f04438; font-size: 12px; min-height: 16px; margin: 0; }
.m-back { display: block; text-align: center; margin-top: 14px; font-size: 12px; color: var(--muted); }

.m-app { height: 100%; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
.m-head {
  flex: none;
  height: 54px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.m-backbtn { width: 34px; height: 34px; border-radius: 9px; font-size: 24px; line-height: 1; color: var(--text); }
.m-backbtn:disabled { opacity: 0; }
.m-head-info { flex: 1; min-width: 0; }
.m-head-info strong { display: block; font-size: 14.5px; color: var(--ink); }
.m-head-info small { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }
.m-head-link { font-size: 12px; color: var(--brand); }

.m-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.m-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 60px 20px; }
.m-conv {
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  border: 1px solid transparent;
}
.m-conv:active { background: #f7f9fd; }
.m-avatar { width: 38px; height: 38px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #7ba2ff, #2f6bff); color: #fff; font-size: 13px; font-weight: 700; }
.m-conv-main { flex: 1; min-width: 0; }
.m-conv-top { display: flex; align-items: center; gap: 6px; }
.m-conv-top strong { font-size: 13.5px; color: var(--ink); }
.m-conv-top time { margin-left: auto; font-size: 11px; color: var(--muted); }
.m-conv-preview { font-size: 12px; color: var(--muted); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-tag { font-size: 10px; border-radius: 4px; padding: 1px 5px; background: #f1f4fa; color: var(--muted); }
.m-tag.ai { background: #eef4ff; color: var(--brand); }
.m-tag.human { background: #ecfdf3; color: #0a9b5b; }
.m-unread { min-width: 18px; height: 18px; border-radius: 9px; background: #f04438; color: #fff; font-size: 11px; display: flex; align-items: center; justify-content: center; padding: 0 5px; }

.m-chat { position: fixed; inset: 54px 0 0; top: calc(54px + env(safe-area-inset-top)); background: #f5f7fb; display: flex; flex-direction: column; z-index: 5; }
.m-msgs { flex: 1; overflow-y: auto; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 10px; }
.m-row { display: flex; gap: 7px; align-items: flex-end; }
.m-row.out { flex-direction: row-reverse; }
.m-row .m-avatar { width: 26px; height: 26px; font-size: 10px; }
.m-row.out .m-avatar { background: linear-gradient(135deg, #7ba2ff, #2f6bff); }
.m-bubble { max-width: 76%; background: #fff; border: 1px solid var(--line); border-radius: 11px; border-bottom-left-radius: 4px; padding: 8px 11px; font-size: 13.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.m-row.out .m-bubble { background: var(--brand); border-color: var(--brand); color: #fff; border-bottom-left-radius: 11px; border-bottom-right-radius: 4px; }
.m-row.ai .m-avatar { background: #eef4ff; color: var(--brand); }
.m-row.ai .m-bubble { background: #f3f7ff; border-color: #dbe8ff; }
.m-sys { text-align: center; font-size: 11px; color: var(--muted); }
.m-sys span { background: #e9edf5; border-radius: 10px; padding: 3px 9px; }

.m-form { flex: none; display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); }
.m-form input { flex: 1; border: 1px solid var(--line); background: #f8fafd; border-radius: 10px; padding: 10px 12px; outline: none; }
.m-form input:focus { border-color: var(--brand); background: #fff; }
.m-form button { padding: 0 16px; border-radius: 10px; background: var(--brand); color: #fff; font-weight: 600; }

.m-toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translate(-50%, 10px);
  background: rgba(23, 32, 56, .94);
  color: #fff;
  font-size: 12px;
  padding: 8px 14px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: .2s;
  z-index: 40;
}
.m-toast.show { opacity: 1; transform: translate(-50%, 0); }
