/* =========================================================
 * base.css —— 设计令牌 / 重置 / 通用组件 / 聊天气泡
 * ========================================================= */

:root {
  --bg:          #070a11;
  --bg-grad:     radial-gradient(1200px 700px at 12% -10%, rgba(79,140,255,.16), transparent 60%),
                 radial-gradient(900px 600px at 105% 5%, rgba(34,211,238,.10), transparent 55%),
                 #070a11;
  --surface:     #0e141f;
  --surface-2:   #141c2a;
  --surface-3:   #1b2536;
  --surface-4:   #223047;
  --line:        #223047;
  --line-soft:   #18212f;

  --text:        #e9eefa;
  --text-2:      #a9b8ce;
  --muted:       #6d7f98;

  --accent:      #4f8cff;
  --accent-2:    #22d3ee;
  --accent-soft: rgba(79,140,255,.14);

  --ok:   #34d399;
  --warn: #fbbf24;
  --bad:  #f87171;
  --ok-soft:   rgba(52,211,153,.14);
  --warn-soft: rgba(251,191,36,.14);
  --bad-soft:  rgba(248,113,113,.14);

  --r:    14px;
  --r-sm: 10px;
  --r-lg: 20px;
  --shadow:    0 20px 50px rgba(0,0,0,.45);
  --shadow-sm: 0 6px 18px rgba(0,0,0,.28);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --header-h: 60px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); text-decoration: none; }
h1,h2,h3,h4,p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

/* --------- 滚动条 --------- */
.scroll { overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--surface-4) transparent; }
.scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: 8px; }
.scroll::-webkit-scrollbar-thumb:hover { background: #2e3f5c; }
.scroll::-webkit-scrollbar-track { background: transparent; }

/* --------- 通用组件 --------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 16px; border-radius: var(--r-sm);
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--line);
  font-size: 13px; font-weight: 500;
  transition: background .16s, border-color .16s, transform .1s, opacity .16s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-4); border-color: #2c3d59; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, #3f7bf0, #5b96ff);
  border-color: transparent; color: #fff;
  box-shadow: 0 6px 18px rgba(79,140,255,.28);
}
.btn-primary:hover { background: linear-gradient(135deg, #4a85f5, #6ba1ff); border-color: transparent; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--bad-soft); border-color: rgba(248,113,113,.32); color: #fca5a5; }
.btn-danger:hover { background: rgba(248,113,113,.22); }
.btn-sm { height: 30px; padding: 0 11px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }

.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 12.5px; color: var(--text-2);
  margin-bottom: 7px; font-weight: 500; letter-spacing: .02em;
}
.field label .req { color: var(--bad); margin-left: 3px; }
.input, .textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 10px 13px; color: var(--text);
  outline: none; transition: border-color .16s, box-shadow .16s, background .16s;
}
.input::placeholder, .textarea::placeholder { color: #55677f; }
.input:focus, .textarea:focus {
  border-color: var(--accent); background: #0b111b;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { resize: vertical; min-height: 92px; line-height: 1.6; }
.input.err, .textarea.err { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.err-msg {
  color: #fca5a5; font-size: 12px; margin-top: 6px; min-height: 16px;
  display: flex; align-items: center; gap: 5px;
}
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--surface-3); color: var(--text-2); border: 1px solid var(--line-soft);
  line-height: 1.6;
}
.badge-wait { background: var(--warn-soft); color: #fcd34d; border-color: rgba(251,191,36,.24); }
.badge-active { background: var(--ok-soft); color: #6ee7b7; border-color: rgba(52,211,153,.24); }
.badge-closed { background: var(--surface-3); color: var(--muted); }
.badge-unread {
  background: #ef4444; color: #fff; border-color: transparent;
  min-width: 19px; height: 19px; justify-content: center; padding: 0 6px;
  font-size: 11px; box-shadow: 0 2px 8px rgba(239,68,68,.4);
}

.avatar {
  width: 36px; height: 36px; border-radius: 11px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: #fff; letter-spacing: .02em;
}
.avatar-sm { width: 28px; height: 28px; border-radius: 9px; font-size: 12px; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(52,211,153,.16); }
.dot.off { background: #64748b; }

/* --------- 弹层 --------- */
.mask {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(4,7,13,.72); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 18px;
  animation: fadeIn .22s ease;
}
.mask[hidden] { display: none; }
.modal {
  width: 100%; max-width: 440px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow); padding: 26px;
  animation: pop .26s cubic-bezier(.22,1,.36,1);
  max-height: calc(100vh - 36px); overflow-y: auto;
}
.modal h2 { font-size: 19px; font-weight: 650; letter-spacing: .01em; }
.modal .sub { color: var(--muted); font-size: 13px; margin-top: 6px; }

@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.97) } to { opacity: 1; transform: none } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: none } }

/* --------- 顶部条 --------- */
.topbar {
  height: var(--header-h); flex: 0 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px; background: rgba(14,20,31,.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(79,140,255,.34);
}
.spacer { flex: 1; }

.conn {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-2);
  padding: 5px 11px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line-soft);
}

/* =========================================================
 * 聊天气泡（访客端 / 客服端共用）
 * ========================================================= */
.chat-body { flex: 1; overflow-y: auto; padding: 20px 20px 8px; }
.msg { display: flex; gap: 10px; margin-bottom: 16px; align-items: flex-end; animation: slideUp .2s ease; }
.msg.me { flex-direction: row-reverse; }
.msg-col { display: flex; flex-direction: column; max-width: min(560px, 74%); }
.msg.me .msg-col { align-items: flex-end; }
.bubble {
  padding: 10px 13px; border-radius: 14px 14px 14px 4px;
  background: var(--surface-3); border: 1px solid var(--line-soft);
  line-height: 1.62; font-size: 14px;
  white-space: pre-wrap; word-break: break-word;
}
.msg.me .bubble {
  border-radius: 14px 14px 4px 14px;
  background: linear-gradient(135deg, #3d78ee, #5391ff);
  border-color: transparent; color: #fff;
  box-shadow: 0 4px 14px rgba(79,140,255,.22);
}
.msg-meta {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--muted); margin-top: 5px; padding: 0 2px;
}
.msg-name { font-size: 11.5px; color: var(--muted); margin-bottom: 5px; padding: 0 2px; }
.tick { font-size: 11px; letter-spacing: -1px; }
.tick.sending { color: #64748b; }
.tick.sent { color: #8ba3c0; }
.tick.read { color: #5eead4; letter-spacing: -2px; }

.sys-line { text-align: center; margin: 12px 0; animation: fadeIn .25s ease; }
.sys-line span {
  display: inline-block; font-size: 12px; color: var(--muted);
  background: var(--surface-2); padding: 5px 13px;
  border-radius: 999px; border: 1px solid var(--line-soft);
}

.day-sep { text-align: center; margin: 16px 0 12px; }
.day-sep span { font-size: 11px; color: #55677f; letter-spacing: .06em; }

/* 正在输入 */
.typing-row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 16px; animation: slideUp .18s ease; }
.typing-bubble {
  background: var(--surface-3); border: 1px solid var(--line-soft);
  border-radius: 14px 14px 14px 4px; padding: 12px 15px;
  display: flex; align-items: center; gap: 5px;
}
.typing-bubble i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-2);
  display: block; animation: bounce 1.25s infinite ease-in-out;
}
.typing-bubble i:nth-child(2) { animation-delay: .16s; }
.typing-bubble i:nth-child(3) { animation-delay: .32s; }
@keyframes bounce {
  0%, 62%, 100% { transform: translateY(0); opacity: .42; }
  32% { transform: translateY(-5px); opacity: 1; }
}

/* 输入区 */
.composer {
  flex: 0 0 auto; border-top: 1px solid var(--line-soft);
  background: rgba(14,20,31,.7); padding: 12px 16px 14px;
}
.composer-box {
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: 8px 8px 8px 14px;
  transition: border-color .16s, box-shadow .16s;
}
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer-box textarea {
  flex: 1; background: none; border: none; outline: none; resize: none;
  max-height: 132px; min-height: 24px; line-height: 1.6; padding: 5px 0;
  font-size: 14px;
}
.composer-box textarea::placeholder { color: #55677f; }
.composer-tip {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11.5px; color: #55677f; margin-top: 8px; padding: 0 3px;
}
.send-btn {
  width: 38px; height: 38px; border-radius: 10px; flex: 0 0 auto;
  background: linear-gradient(135deg, #3f7bf0, #5b96ff); color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .16s, transform .1s;
}
.send-btn:disabled { opacity: .35; cursor: not-allowed; }
.send-btn:not(:disabled):active { transform: scale(.94); }

.empty {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: var(--muted); text-align: center; padding: 30px;
}
.empty svg { opacity: .3; }
.empty .t { font-size: 14px; color: var(--text-2); font-weight: 500; }
.empty .d { font-size: 12.5px; max-width: 300px; line-height: 1.7; }
