:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #f0f1f4;
  --text: #1a1c1f;
  --text-muted: #71767e;
  --border: #e4e6ea;
  --brand: #12b76a;
  --brand-dark: #0b8f53;
  --brand-soft: #e7f8ef;
  --danger: #e5484d;
  --radius: 8px;
  --radius-card: 12px;
  --shadow: 0 8px 24px rgba(20, 24, 33, 0.08);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

button, input, textarea { font: inherit; color: inherit; }

.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 12px; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 7px 14px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover { border-color: #cfd3da; background: #fafbfc; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.ghost { background: transparent; }
.btn.icon { padding: 6px 10px; }

/* 登录 */
.login-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { font-size: 18px; margin: 0; }
.login-card .sub { margin: 0 0 6px; color: var(--text-muted); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
.login-card input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  background: #fff;
  outline: none;
}
.login-card input:focus { border-color: var(--brand); }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0; }

/* 主界面 */
.app {
  height: 100%;
  display: flex;
  overflow: hidden;
}
.sidebar {
  width: 300px;
  min-width: 300px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-head {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #c9ccd2; }
.dot.online { background: var(--brand); }
.conv-list { flex: 1; overflow-y: auto; }
.conv-item {
  padding: 12px 16px;
  border-bottom: 1px solid #f0f1f4;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: center;
}
.conv-item:hover { background: #fafbfc; }
.conv-item.active { background: var(--brand-soft); }
.conv-item .avatar { width: 36px; height: 36px; font-size: 14px; }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.conv-preview {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge {
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  border-radius: 999px;
  padding: 0 6px;
  min-width: 18px;
  text-align: center;
  line-height: 18px;
  height: 18px;
}
.sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}
.sidebar-foot .btn { flex: 1; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.chat-head {
  height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.who { display: flex; align-items: center; gap: 12px; }
.who strong { display: block; font-size: 15px; }
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.empty { margin: auto; color: var(--text-muted); font-size: 13px; }
.msg {
  max-width: 62%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.msg .bubble {
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  word-break: break-word;
  white-space: pre-wrap;
}
.msg .meta { font-size: 11px; color: var(--text-muted); }
.msg img.bubble { padding: 4px; max-width: 240px; display: block; }
.msg.from-customer { align-self: flex-start; }
.msg.from-agent { align-self: flex-end; align-items: flex-end; }
.msg.from-agent .bubble { background: var(--brand); border-color: var(--brand); color: #fff; }
.msg.from-system {
  align-self: center;
  max-width: 78%;
  align-items: center;
}
.msg.from-system .bubble {
  background: var(--surface-muted);
  border-color: transparent;
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 10px;
}

.composer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 20px 16px;
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  outline: none;
}
.composer textarea:focus { border-color: var(--brand); }
.quick-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 10px;
}
.quick-chip {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}
.quick-chip:hover { border-color: var(--brand); color: var(--brand-dark); }

/* 设置弹窗 */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 20, 24, .38);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 20;
}
.modal-card {
  width: 100%;
  max-width: 640px;
  max-height: 86vh;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 24px; }
.block h3 { font-size: 14px; margin: 0 0 10px; }
.block textarea, .block input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  outline: none;
  margin-bottom: 8px;
}
.block textarea:focus, .block input[type="text"]:focus { border-color: var(--brand); }
.switch-line { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 10px; color: var(--text-muted); }
.list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.list-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
}
.list-row .grow { flex: 1; min-width: 0; }
.list-row .tag { font-size: 11px; color: var(--brand-dark); background: var(--brand-soft); border-radius: 4px; padding: 1px 6px; }
.list-row .del { border: none; background: none; color: var(--danger); cursor: pointer; font-size: 12px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { margin-bottom: 0 !important; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: #1f2328;
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 30;
}
