/* ===== 多租户客服系统 · 共享样式（移动优先） ===== */
:root {
  --brand: #2563eb;
  --brand-soft: rgba(37, 99, 235, .12);
  --bg: #0b1120;
  --bg-2: #111a2e;
  --bg-3: #16223b;
  --line: #22304d;
  --text: #e6edf7;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, .35);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body { overflow: hidden; }
body.scroll { overflow: auto; }

a { color: var(--brand); text-decoration: none; }
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px;
  background: var(--bg-3); color: var(--text); border: 1px solid var(--line);
  transition: .18s; white-space: nowrap;
}
.btn:hover { border-color: var(--brand); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .4); color: #fca5a5; }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }
.input, .textarea, .select {
  width: 100%; padding: 11px 13px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  outline: none; transition: .18s;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.textarea { resize: vertical; min-height: 78px; line-height: 1.5; }

.card {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
}
.card + .card { margin-top: 14px; }
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 650; }

.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: var(--bg-3); color: var(--text-2); border: 1px solid var(--line);
}
.tag.ok { background: rgba(34, 197, 94, .12); color: #86efac; border-color: rgba(34, 197, 94, .35); }
.tag.warn { background: rgba(245, 158, 11, .12); color: #fcd34d; border-color: rgba(245, 158, 11, .35); }
.tag.bad { background: rgba(239, 68, 68, .12); color: #fca5a5; border-color: rgba(239, 68, 68, .35); }
.tag.brand { background: var(--brand-soft); color: #93c5fd; border-color: rgba(37, 99, 235, .35); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); display: inline-block; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }

.muted { color: var(--text-2); }
.tiny { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

.empty {
  padding: 44px 20px; text-align: center; color: var(--text-3); font-size: 14px;
}
.empty svg { opacity: .5; margin-bottom: 10px; }

.toast-host {
  position: fixed; left: 50%; top: 18px; transform: translateX(-50%);
  z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none;
  width: max-content; max-width: 88vw;
}
.toast {
  padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 500;
  background: rgba(22, 34, 59, .97); border: 1px solid var(--line);
  box-shadow: var(--shadow); animation: tin .22s ease;
}
.toast.err { border-color: rgba(239, 68, 68, .5); color: #fca5a5; }
.toast.ok { border-color: rgba(34, 197, 94, .5); color: #86efac; }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- 聊天通用 ---------- */
.chat-shell {
  display: flex; flex-direction: column; height: 100dvh;
  background: var(--bg); position: relative;
}
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
  padding-top: max(12px, env(safe-area-inset-top));
  flex-shrink: 0;
}
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--brand), #7c3aed);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 15px; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.avatar.lg { width: 52px; height: 52px; font-size: 20px; }

.msgs {
  flex: 1; overflow-y: auto; padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 12px;
  overscroll-behavior: contain;
}
.msg { display: flex; gap: 8px; max-width: 100%; animation: min .2s ease; }
@keyframes min { from { opacity: 0; transform: translateY(6px); } }
.msg .bubble {
  max-width: min(76vw, 520px); padding: 9px 13px; border-radius: 14px;
  background: var(--bg-3); border: 1px solid var(--line);
  word-break: break-word; white-space: pre-wrap; font-size: 14.5px;
}
.msg.me { justify-content: flex-end; }
.msg.me .bubble {
  background: var(--brand); border-color: var(--brand); color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.other .bubble { border-bottom-left-radius: 4px; }
.msg .meta { font-size: 11px; color: var(--text-3); margin-top: 4px; }
.msg.sys { justify-content: center; }
.msg.sys .bubble {
  background: var(--bg-3); border: 1px solid var(--line);
  color: #cbd5e1; font-size: 13.5px; padding: 10px 15px;
  border-radius: 12px; max-width: 82%; text-align: left; line-height: 1.6;
}
/* 首条欢迎语：加主色左标，视觉上更像"客服打招呼"而不是系统提示 */
.msg.sys.welcome .bubble {
  background: linear-gradient(135deg, rgba(37, 99, 235, .16), rgba(124, 58, 237, .10));
  border-color: rgba(37, 99, 235, .38);
  color: var(--text);
}
.msg .bubble img { max-width: 100%; border-radius: 8px; display: block; }
.msg .time { font-size: 11px; color: var(--text-3); align-self: flex-end; margin-bottom: 2px; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px;
  padding-bottom: max(10px, var(--safe-b));
  background: var(--bg-2); border-top: 1px solid var(--line); flex-shrink: 0;
  width: 100%; max-width: 100%; overflow: hidden;
}
.composer textarea {
  flex: 1 1 0; min-width: 0; width: 0; resize: none;
  max-height: 120px; min-height: 42px;
  padding: 10px 13px; border-radius: 20px; background: var(--bg);
  border: 1px solid var(--line); outline: none; line-height: 1.4;
}
.composer textarea:focus { border-color: var(--brand); }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-3); border: 1px solid var(--line); transition: .18s;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn.primary { background: var(--brand); border-color: var(--brand); }
.icon-btn:disabled { opacity: .45; }

/* ---------- 后台布局 ---------- */
.admin-shell { display: flex; height: 100dvh; }
.side {
  width: 220px; flex-shrink: 0; background: var(--bg-2);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
}
.side .brand {
  padding: 18px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; font-weight: 700;
}
.side nav { padding: 10px; flex: 1; overflow-y: auto; }
.side nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 9px; color: var(--text-2); font-size: 14px; font-weight: 500; margin-bottom: 2px;
}
.side nav a:hover { background: var(--bg-3); color: var(--text); }
.side nav a.on { background: var(--brand-soft); color: #93c5fd; }
.side .foot { padding: 12px; border-top: 1px solid var(--line); }

.main { flex: 1; overflow-y: auto; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  background: rgba(11, 17, 32, .85); backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}
.topbar h2 { margin: 0; font-size: 17px; font-weight: 650; }
.page { padding: 20px; max-width: 1100px; }

.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .k { font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--text-2); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; }
tbody tr:hover { background: rgba(255, 255, 255, .02); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  padding: 9px 14px; font-size: 14px; color: var(--text-2); font-weight: 600;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }

.copy {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
  font-size: 13px; overflow: hidden;
}
.copy code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #93c5fd; }

/* ---------- 登录页 ---------- */
.auth {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: radial-gradient(1000px 600px at 50% -10%, rgba(37, 99, 235, .22), transparent 65%), var(--bg);
}
.auth-card { width: 100%; max-width: 380px; }
.auth-card .logo { display: flex; justify-content: center; margin-bottom: 18px; }
.auth-card h1 { font-size: 20px; text-align: center; margin: 0 0 6px; }
.auth-card .sub { text-align: center; color: var(--text-2); font-size: 13.5px; margin-bottom: 22px; }

@media (max-width: 760px) {
  .side {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 60;
    transform: translateX(-100%); transition: .25s; box-shadow: var(--shadow);
  }
  .side.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 55; }
  .page { padding: 14px; }
  .topbar { padding: 12px 14px; }
  .desk-only { display: none !important; }
}
@media (min-width: 761px) { .mob-only { display: none !important; } }
