:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --primary: #2f6bff;
  --primary-dark: #1f4fd6;
  --text: #1f2733;
  --muted: #7a8699;
  --border: #e6eaf2;
  --bot-bubble: #eef2fb;
  --user-bubble: #2f6bff;
  --danger: #e5484d;
  --ok: #18a957;
  --warn: #f5a524;
  --shadow: 0 6px 24px rgba(31, 39, 51, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a { color: var(--primary); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 18px; margin: 0; display: flex; align-items: center; gap: 10px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 4px rgba(47,107,255,.15); }
.topbar .actions { display: flex; gap: 10px; }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 9px 16px;
  background: var(--primary);
  color: #fff;
  transition: background .15s, transform .05s;
}
button:hover { background: var(--primary-dark); }
button:active { transform: translateY(1px); }
button.ghost { background: transparent; color: var(--primary); border: 1px solid var(--border); }
button.ghost:hover { background: #f0f4ff; }
button.danger { background: var(--danger); }
button.danger:hover { background: #c93b40; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, textarea, select {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  outline: none;
}
input:focus, textarea:focus { border-color: var(--primary); }
label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 6px; }

/* ---------- Chat page ---------- */
.chat-wrap {
  max-width: 880px;
  margin: 22px auto;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 130px);
  overflow: hidden;
}
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.chat-header .who { display: flex; align-items: center; gap: 10px; }
.chat-header .avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, #2f6bff, #6f9bff);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.chat-header .meta { font-size: 12px; color: var(--muted); }

.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; max-width: 82%; }
.msg .ava { width: 30px; height: 30px; border-radius: 50%; flex: 0 0 30px; display:flex; align-items:center; justify-content:center; font-size: 12px; color:#fff; }
.msg.bot .ava { background: #6f9bff; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .ava { background: #8893a8; }
.bubble { padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; }
.msg.bot .bubble { background: var(--bot-bubble); border-top-left-radius: 4px; }
.msg.user .bubble { background: var(--user-bubble); color: #fff; border-top-right-radius: 4px; }
.intent-tag { display:inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; margin-left: 8px; background: #eaf0ff; color: var(--primary); }
.intent-tag.refund { background:#ffeaea; color:#e5484d; }
.intent-tag.order_query { background:#e7f7ee; color:#18a957; }
.intent-tag.tech_support { background:#fff4e0; color:#c97a00; }

.typing span { display:inline-block; width:6px;height:6px;border-radius:50%;background:#9aa6bd;margin:0 2px;animation:blink 1.2s infinite;}
.typing span:nth-child(2){animation-delay:.2s} .typing span:nth-child(3){animation-delay:.4s}
@keyframes blink{0%,80%,100%{opacity:.3}40%{opacity:1}}

.composer { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--border); align-items: flex-end; }
.composer textarea { flex: 1; resize: none; height: 46px; max-height: 120px; }
.composer .send { height: 46px; }

.rating-bar { display:flex; align-items:center; gap:8px; padding: 8px 16px; border-top:1px solid var(--border); font-size:13px; color:var(--muted); flex-wrap: wrap;}
.stars { display:inline-flex; gap:2px; }
.stars .star { font-size:20px; color:#d3d9e6; cursor:pointer; }
.stars .star.on { color:#f5a524; }

.notice { padding: 10px 14px; border-radius: 10px; margin: 4px 0; font-size: 13px; }
.notice.warn { background:#fff4e0; color:#9a6400; }
.notice.err { background:#ffeaea; color:#b4262b; }
.notice.ok { background:#e7f7ee; color:#0f7a3d; }

/* ---------- Admin ---------- */
.admin-wrap { max-width: 1100px; margin: 22px auto; padding: 0 18px; }
.grid { display: grid; gap: 16px; }
.cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.card .num { font-size: 28px; font-weight: 700; }
.card .lbl { color: var(--muted); font-size: 13px; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; }
.panel h2 { margin: 0 0 14px; font-size: 16px; }
.row { display:flex; gap: 18px; flex-wrap: wrap; }
.row > .col { flex: 1 1 360px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
tr.clickable:hover { background: #f7f9ff; cursor: pointer; }
.badge { font-size: 12px; padding: 2px 9px; border-radius: 999px; background: #eef2fb; color: var(--primary); }
.badge.active { background:#e7f7ee; color:#0f7a3d; }
.badge.handoff { background:#ffeaea; color:#b4262b; }
.badge.resolved { background:#eef2fb; color:#5a6b8c; }
.badge.pending { background:#fff4e0; color:#9a6400; }
.badge.handled { background:#e7f7ee; color:#0f7a3d; }

.dist { display:flex; align-items:center; gap:10px; margin: 6px 0; font-size:13px; }
.dist .bar { flex:1; height: 12px; background:#eef2fb; border-radius: 8px; overflow:hidden; }
.dist .bar > i { display:block; height:100%; background: var(--primary); border-radius:8px; }
.dist .cnt { width: 30px; text-align:right; color: var(--muted); }

.login-card { max-width: 380px; margin: 8vh auto; }
.tabs { display:flex; gap: 6px; margin-bottom: 16px; }
.tabs button { flex:1; background: transparent; color: var(--muted); border:1px solid var(--border); }
.tabs button.active { background: var(--primary); color:#fff; border-color: var(--primary); }
.field { margin-bottom: 12px; }
.field input { width: 100%; }
.muted { color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }
.conv-detail { background:#fafbfe; border:1px solid var(--border); border-radius:10px; padding:14px; max-height: 420px; overflow-y:auto; }
.conv-detail .m { margin-bottom: 10px; }
.conv-detail .m .who { font-size:12px; color:var(--muted); margin-bottom:2px; }
.conv-detail .m .b { display:inline-block; padding:8px 12px; border-radius:10px; max-width: 80%; }
.conv-detail .m.user .b { background: var(--user-bubble); color:#fff; }
.conv-detail .m.bot .b { background:#fff; border:1px solid var(--border); }
.empty { color: var(--muted); text-align:center; padding: 30px; }
