/* 小程序客服后台样式 */
:root {
  --green: #07c160;
  --green-dark: #06ad56;
  --bg: #f2f4f7;
  --panel: #ffffff;
  --border: #e6e9ee;
  --text: #1c2530;
  --muted: #8a95a5;
  --danger: #e34d4d;
  --warn: #d98a00;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(21, 34, 50, .08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body.is-auth { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

a { color: var(--green-dark); text-decoration: none; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); font-size: 12px; }
.ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- 按钮 ---------------- */

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  background: #f4f6f9;
  color: var(--text);
  transition: all .15s ease;
  line-height: 1.4;
}
.btn:hover { background: #eaeef4; }
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.ghost { background: #fff; border-color: var(--border); }
.btn.ghost:hover { border-color: #cfd6e0; background: #fafbfd; }
.btn.danger { color: var(--danger); }
.btn.ghost.danger { border-color: #f3d3d3; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.block { width: 100%; padding: 11px; font-size: 15px; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---------------- 登录 ---------------- */

.login-wrap, .setup-tip {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #eef4ff 0%, #f7fbf8 55%, #ffffff 100%);
  padding: 24px;
  flex-direction: column;
}
.login-card {
  width: 360px;
  max-width: 100%;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.login-logo {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: linear-gradient(150deg, #34e07f, #07c160);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
  margin-bottom: 16px;
  box-shadow: 0 8px 20px rgba(7, 193, 96, .28);
}
.login-card h1 { font-size: 19px; margin: 0 0 6px; }
.login-sub { color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field.compact { margin-bottom: 10px; }
input[type="text"], input[type="password"], input[type="search"], textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  color: var(--text);
  background: #fff;
  outline: none;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(7, 193, 96, .12); }
textarea { resize: vertical; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; margin: 10px 0; color: #46586d; }
.check input { margin-top: 2px; }

/* ---------------- 顶栏 ---------------- */

.topbar {
  height: 58px;
  flex: 0 0 58px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(7, 193, 96, .16);
}
.stats { display: flex; gap: 20px; margin-left: 8px; }
.stat { display: flex; flex-direction: column; line-height: 1.3; }
.stat i { font-style: normal; font-size: 11px; color: var(--muted); }
.stat b { font-size: 15px; }
.tools { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.who { font-size: 12px; color: #46586d; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- 三栏布局 ---------------- */

.layout { flex: 1 1 auto; display: flex; min-height: 0; }
.pane { background: #fff; display: flex; flex-direction: column; min-height: 0; }
.pane-list { width: 300px; flex: 0 0 300px; border-right: 1px solid var(--border); }
.pane-chat { flex: 1 1 auto; background: #f7f9fb; min-width: 0; }
.pane-side { width: 288px; flex: 0 0 288px; border-left: 1px solid var(--border); overflow-y: auto; }

.pane-head { padding: 12px; display: flex; gap: 8px; border-bottom: 1px solid var(--border); }
.pane-head input { flex: 1; }
.conv-filter {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; font-size: 12px; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.conv-list { flex: 1; overflow-y: auto; }
.conv {
  display: flex; gap: 10px; padding: 11px 12px;
  border-bottom: 1px solid #f1f4f8; cursor: pointer;
}
.conv:hover { background: #fafbfd; }
.conv.active { background: #eefaf3; }
.conv-avatar {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 10px;
  background: linear-gradient(150deg, #d7f5e4, #b8eccd);
  color: #0c7a41;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; }
.conv-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.conv-bottom { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.conv-preview {
  flex: 1; font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); }
.unread { font-size: 11px; color: #fff; background: var(--danger); border-radius: 9px; padding: 1px 6px; }

/* ---------------- 聊天区 ---------------- */

.chat-head {
  flex: 0 0 auto;
  height: 62px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
}
.chat-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(150deg, #34e07f, #07c160);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.chat-name { font-weight: 600; font-size: 14px; }
.chat-openid { font-size: 11px; }
.chat-meta { display: flex; align-items: center; gap: 10px; }

.badge { font-size: 11px; padding: 3px 9px; border-radius: 20px; background: #f1f3f6; color: #6b7b8d; }
.badge.ok { background: #e8f9ef; color: #07874a; }
.badge.warn { background: #fdf2e2; color: var(--warn); }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: #f1f3f6; color: #6b7b8d; }
.tag.ok { background: #e8f9ef; color: #07874a; }
.tag.warn { background: #fdf2e2; color: var(--warn); }

.msg-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 20px 10px;
  display: flex; flex-direction: column; gap: 4px;
}
.time-divider {
  align-self: center;
  font-size: 11px; color: #9aa6b5;
  background: rgba(255,255,255,.7);
  padding: 3px 10px; border-radius: 10px; margin: 10px 0 6px;
}
.event-line {
  align-self: center; font-size: 12px; color: #8a95a5;
  background: #eaeef3; padding: 4px 12px; border-radius: 12px; margin: 6px 0;
}
.msg { display: flex; margin: 4px 0; }
.msg.out { justify-content: flex-end; }
.bubble {
  max-width: min(560px, 72%);
  background: #fff;
  border-radius: 14px;
  padding: 9px 13px;
  box-shadow: 0 1px 2px rgba(21, 34, 50, .06);
  word-break: break-word;
}
.msg.out .bubble { background: #dcf8e7; }
.msg-text { font-size: 14px; line-height: 1.6; white-space: pre-wrap; }
.msg-img { max-width: 220px; max-height: 220px; border-radius: 8px; cursor: zoom-in; display: block; }
.msg-meta { font-size: 11px; color: #9aa6b5; margin-top: 5px; text-align: right; }
.msg-error { font-size: 11px; color: var(--danger); margin-top: 4px; }
.fail { color: var(--danger); }

.composer {
  flex: 0 0 auto;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 10px 16px 14px;
}
.composer-tools { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.file-btn { cursor: pointer; }
.select.small { width: auto; padding: 5px 8px; font-size: 12px; }
.composer-input { display: flex; gap: 10px; align-items: flex-end; }
.composer-input textarea {
  flex: 1; min-height: 62px; max-height: 160px; resize: vertical;
  line-height: 1.6;
}
.composer-input .btn { height: 40px; padding: 0 22px; }
.composer-tip { margin-top: 6px; color: var(--warn); }

/* ---------------- 右栏 ---------------- */

.side-block { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.side-block h3 { margin: 0 0 10px; font-size: 13px; color: #33465c; }
.kv { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; padding: 4px 0; }
.kv span { color: var(--muted); flex: 0 0 auto; }
.kv b, .kv code { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-actions { display: flex; gap: 8px; margin-top: 10px; }
.tips { margin: 0; padding-left: 16px; color: #6b7b8d; font-size: 12px; line-height: 1.8; }

/* ---------------- 弹窗 ---------------- */

.modal {
  position: fixed; inset: 0;
  background: rgba(18, 26, 38, .45);
  display: none; align-items: center; justify-content: center;
  z-index: 50; padding: 20px;
}
.modal.open { display: flex; }
.modal-card {
  background: #fff; border-radius: 14px; width: 520px; max-width: 100%;
  max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(10, 20, 32, .28);
}
.modal-card.wide { width: 760px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-close {
  border: none; background: transparent; font-size: 22px; line-height: 1;
  color: #9aa6b5; cursor: pointer;
}
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.modal-msg { font-size: 12px; color: #46586d; margin-top: 10px; min-height: 16px; }
.hint-box {
  background: #f7f9fb; border: 1px dashed var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 12px; color: #46586d; margin-top: 12px;
}
.hint-box code { display: block; margin: 6px 0; word-break: break-all; color: #1c2530; }
.form-row { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.form-row input, .form-row select { flex: 1; min-width: 120px; }

.table-wrap { max-height: 44vh; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.table { width: 100%; border-collapse: collapse; font-size: 12px; }
.table th, .table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #f1f4f8; }
.table th { background: #fafbfd; color: #6b7b8d; font-weight: 500; position: sticky; top: 0; }
.table tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 6px; white-space: nowrap; }

/* ---------------- 其它 ---------------- */

.empty { padding: 40px 16px; text-align: center; color: #9aa6b5; font-size: 13px; }
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%) translateY(20px);
  background: rgba(20, 28, 40, .9); color: #fff;
  padding: 10px 18px; border-radius: 22px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: all .22s ease; z-index: 90;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.setup-tip h2 { margin-top: 0; }
.setup-tip p { color: #46586d; }

/* ---------------- 响应式 ---------------- */

@media (max-width: 1180px) {
  .pane-side { display: none; }
}
@media (max-width: 860px) {
  .stats { display: none; }
  .pane-list { width: 240px; flex-basis: 240px; }
  .tools .btn { padding: 6px 9px; font-size: 12px; }
}
@media (max-width: 640px) {
  .pane-list { display: none; }
  .topbar { gap: 10px; padding: 0 10px; }
}
