:root {
  --brand: #0e9f6e;
  --brand-dark: #0b7d56;
  --brand-soft: #e6f5ef;
  --ink: #14251f;
  --ink-2: #4a5c55;
  --line: #e3e9e6;
  --bg: #f2f5f3;
  --warn: #d97706;
  --danger: #dc2626;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }

/* ============ 客服端 ============ */
.chat-body { display: flex; align-items: center; justify-content: center; background: #e8eeea; }
.phone {
  width: 100%; max-width: 480px; height: 100%; max-height: 880px;
  display: flex; flex-direction: column; background: var(--bg);
  box-shadow: 0 12px 48px rgba(15, 40, 30, .16); border-radius: 16px; overflow: hidden;
}
@media (max-width: 520px) { .phone { max-height: 100vh; border-radius: 0; } }

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: #fff; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, var(--brand), #35c48f);
  color: #fff; font-size: 18px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.brand-name { font-size: 15px; font-weight: 600; }
.brand-sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.header-actions { display: flex; gap: 8px; }
.link-btn {
  background: transparent; border: 1px solid var(--line); color: var(--ink-2);
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
}
.link-btn:hover { border-color: var(--brand); color: var(--brand); }

.notice {
  margin: 8px 12px 0; padding: 8px 12px; border-radius: 8px; font-size: 12.5px;
  background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa;
}
.notice.human { background: var(--brand-soft); color: var(--brand-dark); border-color: #b7e4d0; }

.chat-main { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; gap: 8px; align-items: flex-start; animation: pop .18s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.msg.user { flex-direction: row-reverse; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 30px; font-size: 12px;
  display: flex; align-items: center; justify-content: center; color: #fff; background: var(--brand);
}
.msg.user .avatar { background: #9aa8a2; }
.bubble {
  max-width: 76%; padding: 10px 12px; border-radius: 12px; font-size: 14.5px; line-height: 1.6;
  background: #fff; border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word;
}
.msg.user .bubble { background: var(--brand); border-color: var(--brand); color: #fff; }
.msg.human .bubble { background: #fff; border-color: var(--brand); border-left: 3px solid var(--brand); }
.msg.system .bubble { background: #f1f5f3; color: var(--ink-2); font-size: 13px; border-style: dashed; }
.meta { margin-top: 6px; font-size: 11px; color: #8b9992; display: flex; flex-wrap: wrap; gap: 6px; }
.tag { background: #eef2f0; border-radius: 4px; padding: 1px 5px; }
.tag.pending { background: #fef3c7; color: #92400e; }
.typing span { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #b6c2bc; margin-right: 3px; animation: blink 1s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

.quick { display: flex; gap: 6px; overflow-x: auto; padding: 0 14px 8px; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  font-size: 12.5px; padding: 6px 12px; border-radius: 999px;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }

.chat-footer { display: flex; gap: 8px; padding: 10px 12px 14px; background: #fff; border-top: 1px solid var(--line); }
#input {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
  font-size: 14.5px; font-family: inherit; outline: none; max-height: 96px;
}
#input:focus { border-color: var(--brand); }
.send-btn {
  background: var(--brand); color: #fff; border: none; border-radius: 10px; padding: 0 18px; font-size: 14px; font-weight: 600;
}
.send-btn:disabled { background: #b9c6c0; cursor: not-allowed; }

.mask { position: fixed; inset: 0; background: rgba(10, 25, 18, .45); display: flex; align-items: center; justify-content: center; z-index: 20; }
.rate-card { width: 320px; background: #fff; border-radius: 14px; padding: 20px; }
.rate-title { font-size: 16px; font-weight: 600; text-align: center; }
.stars { display: flex; justify-content: center; gap: 8px; margin: 14px 0 6px; }
.stars span { font-size: 30px; color: #d7dedb; cursor: pointer; transition: .15s; }
.stars span.on { color: #f59e0b; transform: scale(1.08); }
.rate-hint { text-align: center; font-size: 12.5px; color: var(--ink-2); min-height: 18px; }
#rateComment { width: 100%; margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-family: inherit; font-size: 13.5px; resize: none; }
.rate-actions { display: flex; gap: 8px; margin-top: 12px; }
.ghost-btn, .primary-btn { flex: 1; padding: 9px; border-radius: 8px; font-size: 14px; border: 1px solid var(--line); background: #fff; color: var(--ink-2); }
.primary-btn { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }

/* ============ 管理后台 ============ */
.admin-body { background: #0e1512; color: #e6efea; }
.admin {
  max-width: 1440px; margin: 0 auto; padding: 18px 22px 40px;
}
.admin-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.admin-title { font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.admin-title .logo { width: 30px; height: 30px; font-size: 15px; border-radius: 8px; }
.admin-sub { font-size: 12px; color: #7f948c; margin-top: 3px; }
.engine-badge { font-size: 12px; padding: 5px 10px; border-radius: 999px; border: 1px solid #24332c; background: #14201b; color: #8fd8b8; }
.engine-badge.off { color: #f0b26b; border-color: #3a2f1c; background: #221b12; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #14201b; border: 1px solid #223029; border-radius: 12px; padding: 14px 16px; }
.kpi .k-label { font-size: 12px; color: #7f948c; }
.kpi .k-value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: .5px; }
.kpi .k-foot { font-size: 11.5px; color: #5f736b; margin-top: 4px; }
.kpi.accent .k-value { color: #4ade9b; }
.kpi.warn .k-value { color: #fbbf24; }

.panels { display: grid; grid-template-columns: 320px 1fr; gap: 14px; align-items: start; }
@media (max-width: 1000px) { .panels { grid-template-columns: 1fr; } }
.panel { background: #14201b; border: 1px solid #223029; border-radius: 12px; overflow: hidden; }
.panel-head { padding: 12px 14px; border-bottom: 1px solid #223029; font-size: 13.5px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.panel-body { padding: 12px 14px; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 12px; border-bottom: 1px solid #223029; }
.filter {
  font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid #26352e; background: #101a16; color: #93a79e;
}
.filter.on { background: #1c3a2c; border-color: #2f6b4d; color: #8ce8b6; }
.search {
  width: 100%; margin-top: 8px; background: #101a16; border: 1px solid #26352e; color: #dfeae5;
  border-radius: 8px; padding: 7px 10px; font-size: 13px; outline: none; font-family: inherit;
}
.conv-list { max-height: 640px; overflow-y: auto; }
.conv {
  padding: 10px 14px; border-bottom: 1px solid #1b2721; cursor: pointer;
}
.conv:hover { background: #18251f; }
.conv.on { background: #1a2f25; border-left: 2px solid #4ade9b; }
.conv-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.conv-name { font-size: 13.5px; font-weight: 600; }
.conv-time { font-size: 11px; color: #5f736b; }
.conv-msg { font-size: 12px; color: #8b9d95; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-tags { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.badge { font-size: 10.5px; padding: 1px 6px; border-radius: 4px; background: #1e2c26; color: #8fb3a3; border: 1px solid #26352e; }
.badge.human { background: #3a2418; color: #f0b26b; border-color: #4a3220; }
.badge.pending { background: #3a2f14; color: #f5d17a; border-color: #4a3f1c; }
.badge.closed { background: #1b2420; color: #6b7d75; }
.badge.intent { background: #16281f; color: #74d3a3; }

.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 12px 14px; border-bottom: 1px solid #223029; }
.detail-meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: #7f948c; margin-top: 6px; }
.detail-actions { display: flex; gap: 6px; }
.mini-btn { font-size: 12px; padding: 6px 10px; border-radius: 7px; border: 1px solid #2b3a32; background: #16241d; color: #b7cbc1; }
.mini-btn:hover { border-color: #4ade9b; color: #8ce8b6; }
.mini-btn.danger:hover { border-color: #f87171; color: #fca5a5; }

.thread { max-height: 460px; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.t-msg { display: flex; gap: 8px; }
.t-msg.user { flex-direction: row-reverse; }
.t-avatar { width: 26px; height: 26px; border-radius: 50%; font-size: 11px; display: flex; align-items: center; justify-content: center; background: #2b3a32; color: #b7cbc1; flex: 0 0 26px; }
.t-msg.agent .t-avatar { background: #1c4634; color: #8ce8b6; }
.t-msg.human .t-avatar { background: #5a3a1a; color: #f0b26b; }
.t-bubble { max-width: 78%; background: #101a16; border: 1px solid #223029; border-radius: 10px; padding: 9px 11px; font-size: 13.5px; line-height: 1.65; white-space: pre-wrap; }
.t-msg.user .t-bubble { background: #1c3a2c; border-color: #2f6b4d; }
.t-meta { font-size: 11px; color: #5f736b; margin-top: 5px; display: flex; gap: 6px; flex-wrap: wrap; }
.kb-ref { font-size: 11px; color: #74d3a3; background: #12241c; border: 1px solid #1e3d2d; border-radius: 4px; padding: 1px 6px; }

.reply-box { border-top: 1px solid #223029; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.reply-box textarea {
  width: 100%; background: #101a16; border: 1px solid #26352e; color: #dfeae5; border-radius: 8px;
  padding: 9px 11px; font-size: 13.5px; font-family: inherit; resize: none; outline: none;
}
.reply-box textarea:focus { border-color: #4ade9b; }
.reply-row { display: flex; gap: 8px; align-items: center; }
.reply-row input { flex: 0 0 140px; background: #101a16; border: 1px solid #26352e; color: #dfeae5; border-radius: 8px; padding: 8px 10px; font-size: 13px; outline: none; font-family: inherit; }

.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
@media (max-width: 900px) { .charts { grid-template-columns: 1fr; } }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 12.5px; }
.bar-label { flex: 0 0 84px; color: #93a79e; text-align: right; }
.bar-track { flex: 1; height: 8px; background: #101a16; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #0e9f6e, #4ade9b); border-radius: 999px; }
.bar-value { flex: 0 0 34px; color: #cfded7; text-align: right; }
.empty { padding: 26px 14px; text-align: center; color: #6b7d75; font-size: 13px; }

table.faq { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.faq th, table.faq td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #1b2721; }
table.faq th { color: #7f948c; font-weight: 500; }
table.faq td { color: #cfded7; vertical-align: top; }
.link { color: #8ce8b6; text-decoration: none; }
