/* ============================================
   在线客服 - 用户端样式
   ============================================ */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --grad-brand: linear-gradient(160deg, #1e3a8a 0%, #2563eb 55%, #0284c7 100%);
  --grad-bubble: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
  --bg: #eef2f8;
  --panel: #ffffff;
  --text: #1e293b;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --border: #e2e8f0;
  --bubble-agent: #f1f5f9;
  --online: #22c55e;
  --danger: #ef4444;
  --radius-lg: 18px;
  --shadow: 0 24px 64px rgba(15, 23, 42, 0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

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

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ---------- 主容器 ---------- */
.app {
  display: flex;
  width: 100%;
  max-width: 1120px;
  height: min(92vh, 860px);
  min-height: 540px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--panel);
}

/* ---------- 品牌区 ---------- */
.brand-panel {
  flex: 0 0 360px;
  background: var(--grad-brand);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 44px 40px;
  position: relative;
  overflow: hidden;
}
.brand-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(420px 300px at 85% -10%, rgba(255, 255, 255, 0.18), transparent 60%),
    radial-gradient(360px 260px at -10% 110%, rgba(255, 255, 255, 0.12), transparent 60%);
  pointer-events: none;
}
.brand { position: relative; z-index: 1; }
.brand-logo {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.28);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(6px);
  margin-bottom: 22px;
}
.brand-name {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: 10px;
}
.brand-slogan {
  font-size: 14px;
  letter-spacing: 4px;
  color: rgba(255, 255, 255, 0.82);
}
.brand-features {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; gap: 16px;
}
.feature {
  display: flex; align-items: center; gap: 12px;
  font-size: 15px;
  color: rgba(255, 255, 255, 0.94);
}
.feature .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.22);
}
.brand-footer {
  position: relative; z-index: 1;
  font-size: 13px;
  letter-spacing: 2px;
  color: rgba(255, 255, 255, 0.6);
  text-align: center;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
}

/* ---------- 聊天区 ---------- */
.chat-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: #fbfdff;
}
.header-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--grad-bubble);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 600;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.32);
}
.header-name { font-size: 16px; font-weight: 600; }
.header-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--text-2); margin-top: 2px;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--online);
  position: relative;
}
.status-dot.pulse::after {
  content: "";
  position: absolute; inset: -4px;
  border-radius: 50%;
  background: rgba(34, 197, 94, 0.35);
  animation: pulse 1.8s ease-out infinite;
}
.status-dot.off { background: #94a3b8; }
.status-dot.off::after { display: none; }
.status-dot.error { background: var(--danger); }
.status-dot.error::after { display: none; }
@keyframes pulse {
  0% { transform: scale(0.6); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* ---------- 消息区 ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background:
    radial-gradient(600px 300px at 100% 0%, rgba(37, 99, 235, 0.03), transparent 60%),
    #fff;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: #d3dce8; border-radius: 3px; }
.messages::-webkit-scrollbar-track { background: transparent; }

.date-divider {
  text-align: center;
  margin: 18px 0 14px;
  font-size: 12px;
  color: var(--text-3);
}
.date-divider span {
  background: #f1f5f9;
  padding: 3px 12px;
  border-radius: 10px;
}

.msg-row {
  display: flex;
  margin-bottom: 16px;
  align-items: flex-end;
  animation: msg-in 0.22s ease-out;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 顾客消息：右侧 */
.msg-row.customer { justify-content: flex-end; }
.msg-row.customer .msg-bubble {
  background: var(--grad-bubble);
  color: #fff;
  border-radius: 14px 14px 4px 14px;
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.22);
}

/* 客服消息：左侧 */
.msg-row.agent { justify-content: flex-start; gap: 10px; }
.msg-row.agent .avatar {
  width: 34px; height: 34px; flex: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #0ea5e9, #06b6d4);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600;
}
.msg-row.agent .msg-bubble {
  background: var(--bubble-agent);
  color: var(--text);
  border-radius: 14px 14px 14px 4px;
}

.msg-body { max-width: 68%; min-width: 0; }
.msg-bubble {
  padding: 10px 14px;
  font-size: 14.5px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-time {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 5px;
  padding: 0 4px;
}
.customer .msg-time { text-align: right; }

/* 系统消息：居中 */
.msg-row.system { justify-content: center; }
.msg-row.system .msg-system-pill {
  background: #f1f5f9;
  color: var(--text-2);
  font-size: 12.5px;
  padding: 6px 14px;
  border-radius: 16px;
  max-width: 80%;
  text-align: center;
  line-height: 1.5;
  word-break: break-word;
}

/* ---------- 输入区 ---------- */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
  background: #fbfdff;
}
.input-area textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 14.5px;
  font-family: inherit;
  line-height: 1.5;
  max-height: 120px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-area textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.input-area textarea::placeholder { color: var(--text-3); }

.send-btn {
  display: flex; align-items: center; gap: 6px;
  height: 42px; padding: 0 18px;
  border: none; border-radius: 12px;
  background: var(--grad-bubble);
  color: #fff;
  font-size: 14.5px; font-weight: 500;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s, opacity 0.15s;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28);
}
.send-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(37, 99, 235, 0.36); }
.send-btn:active:not(:disabled) { transform: translateY(0); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
  animation: fade-in 0.2s ease-out;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 360px;
  background: #fff;
  border-radius: 20px;
  padding: 36px 32px 32px;
  text-align: center;
  box-shadow: 0 32px 80px rgba(15, 23, 42, 0.22);
  animation: pop-in 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.92) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-icon {
  width: 60px; height: 60px;
  margin: 0 auto 16px;
  border-radius: 18px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
}
.modal h2 { font-size: 20px; margin-bottom: 8px; }
.modal-desc { font-size: 13.5px; color: var(--text-2); margin-bottom: 22px; }
.modal input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.modal input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.modal-error {
  min-height: 18px;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--danger);
}
button.primary {
  width: 100%;
  height: 44px;
  margin-top: 6px;
  border: none;
  border-radius: 12px;
  background: var(--grad-bubble);
  color: #fff;
  font-size: 15px; font-weight: 500;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28);
}
button.primary:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(37, 99, 235, 0.36); }
button.primary:active { transform: translateY(0); }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- 响应式 ---------- */
@media (max-width: 880px) {
  body { padding: 0; }
  .app { height: 100vh; min-height: 100vh; border-radius: 0; }
  .brand-panel { display: none; }
  .msg-body { max-width: 82%; }
}
