/* ============ 客服工作台 / 管理后台 ============ */
:root {
  --brand: #e02020;
  --brand-2: #ff5a3c;
  --ink: #171b22;
  --ink-2: #4b5563;
  --ink-3: #8a94a6;
  --line: #e9edf3;
  --bg: #f4f6fa;
  --side: #171b24;
  --side-2: #1f2530;
  --green: #00a870;
  --blue: #2f7cf6;
  --purple: #8a5cf6;
  --gold: #ffb400;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", Arial, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- 登录 ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #14181f, #232a3a 55%, #3a1f22); }
.login-card { width: 380px; background: #fff; border-radius: 16px; padding: 34px 30px; box-shadow: 0 24px 60px rgba(0,0,0,.34); }
.login-card .lg { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-card .lg .mark { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; }
.login-card .lg b { font-size: 18px; }
.login-card h3 { font-size: 20px; margin-bottom: 4px; }
.login-card .sub { color: var(--ink-3); font-size: 13px; margin-bottom: 22px; }
.f-row { margin-bottom: 14px; }
.f-row label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.f-row input { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 0 13px; font-size: 14px; font-family: inherit; outline: none; }
.f-row input:focus { border-color: var(--brand); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 42px; padding: 0 20px; border-radius: 10px; font-size: 14px; font-weight: 600; border: 1px solid transparent; }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn-danger { background: #fff; border-color: #f5b5b5; color: var(--brand); }
.btn-sm { height: 32px; padding: 0 14px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.login-err { color: var(--brand); font-size: 13px; min-height: 20px; margin-top: 8px; }
.login-foot { margin-top: 18px; text-align: center; font-size: 12px; color: var(--ink-3); }

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 200px; flex-shrink: 0; background: var(--side); color: rgba(255,255,255,.72); display: flex; flex-direction: column; }
.sidebar .sb-top { padding: 18px 18px 14px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .sb-top .mark { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; }
.sidebar .sb-top b { color: #fff; font-size: 15px; }
.sidebar .sb-top small { display: block; font-size: 11px; opacity: .6; }
.sidebar nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-radius: 9px;
  font-size: 14px; margin-bottom: 3px; color: rgba(255,255,255,.72); transition: all .16s; position: relative;
}
.sidebar nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar nav a.on { background: linear-gradient(135deg, rgba(224,32,32,.9), rgba(255,90,60,.8)); color: #fff; }
.sidebar nav a .cnt { margin-left: auto; background: var(--brand); color: #fff; font-size: 11px; min-width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 9px; padding: 0 5px; }
.sidebar nav a.on .cnt { background: rgba(0,0,0,.28); }
.sidebar nav a .ic { width: 18px; text-align: center; }
.sb-user { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: 9px; }
.sb-user .av { width: 32px; height: 32px; border-radius: 50%; background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.sb-user .nm { color: #fff; font-size: 13px; font-weight: 600; }
.sb-user .rl { font-size: 11px; opacity: .6; }
.sb-user .out { margin-left: auto; background: none; border: 0; color: rgba(255,255,255,.5); font-size: 12px; }
.sb-user .out:hover { color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar-c { height: 56px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 0 20px; gap: 14px; flex-shrink: 0; }
.topbar-c h2 { font-size: 17px; }
.topbar-c .status { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.dot-on { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(0,168,112,.16); }
.dot-off { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.content { flex: 1; padding: 18px; overflow: auto; }

/* ---------- 未回复红色提醒条（回复后才消失） ---------- */
.alertbar {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  margin: 0; padding: 10px 18px;
  background: #fff1f0; border-bottom: 1px solid #ffccc7; color: #a8071a;
  font-size: 13px; animation: alertIn .22s ease-out;
}
.alertbar .ab-ic { font-size: 16px; line-height: 1; animation: alertPulse 1.1s ease-in-out infinite; }
.alertbar .ab-tx { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alertbar .ab-tx b { color: #cf1322; }
.alertbar .ab-who { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.alertbar .ab-who b {
  cursor: pointer; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: #fff; border: 1px solid #ffa39e; color: #cf1322;
}
.alertbar .ab-who b:hover { background: #cf1322; color: #fff; border-color: #cf1322; }
.alertbar .ab-who i { font-style: normal; color: #cf1322; opacity: .8; }
.alertbar .ab-go {
  flex-shrink: 0; height: 28px; padding: 0 14px; border: 0; border-radius: 999px;
  background: #cf1322; color: #fff; font-size: 13px; font-family: inherit; cursor: pointer;
}
.alertbar .ab-go:hover { background: #a8071a; }
@keyframes alertIn { from { transform: translateY(-100%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes alertPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }

/* ---------- 卡片 / 统计 ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.kpi .lb { font-size: 13px; color: var(--ink-3); }
.kpi .vl { font-size: 28px; font-weight: 800; letter-spacing: -1px; margin-top: 4px; }
.kpi .vl.brand { color: var(--brand); }
.kpi .vl.green { color: var(--green); }
.kpi .vl.blue { color: var(--blue); }
.kpi .vl.gold { color: var(--gold); }
.kpi .ex { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 16px; }
.panel-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.panel-h h3 { font-size: 15px; }
.panel-h .r { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.panel-b { padding: 16px 18px; }
.panel-b.flush { padding: 0; }

table.tb { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tb th { background: #fafbfd; text-align: left; padding: 11px 14px; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tb td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tb tr:last-child td { border-bottom: 0; }
table.tb tbody tr:hover { background: #fafbfd; }
table.tb td input[type=checkbox] { cursor: pointer; }

.tag { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 6px; background: var(--bg); color: var(--ink-2); }
.tag.red { background: rgba(224,32,32,.1); color: var(--brand); }
.tag.green { background: rgba(0,168,112,.1); color: var(--green); }
.tag.blue { background: rgba(47,124,246,.1); color: var(--blue); }
.tag.gold { background: rgba(255,180,0,.14); color: #a97200; }
.tag.gray { background: #eef1f6; color: var(--ink-3); }

.empty { text-align: center; padding: 46px 20px; color: var(--ink-3); font-size: 14px; }
.empty .ico { font-size: 34px; opacity: .35; margin-bottom: 8px; }

/* ---------- 会话工作台 ---------- */
.work { display: flex; gap: 14px; height: calc(100vh - 92px); }
.work-list { width: 300px; flex-shrink: 0; background: #fff; border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.wl-tabs { display: flex; border-bottom: 1px solid var(--line); }
.wl-tabs div { flex: 1; text-align: center; padding: 11px 0; font-size: 13px; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; }
.wl-tabs div.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.wl-search { padding: 10px; border-bottom: 1px solid var(--line); }
.wl-search input { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 0 11px; font-size: 13px; outline: none; font-family: inherit; }
.wl-search input:focus { border-color: var(--brand); }
.wl-filter { padding: 9px 10px; border-bottom: 1px solid var(--line); }
.wl-filter select {
  width: 100%; height: 32px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px;
  font-size: 13px; font-family: inherit; outline: none; background: #fff;
}
.wl-filter select:focus { border-color: var(--brand); }
.wl-items { flex: 1; overflow-y: auto; }
.site-badge {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 4px;
  background: rgba(47,124,246,.1); color: var(--blue); max-width: 96px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle;
}
.wl-item { padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; gap: 10px; transition: background .15s; }
.wl-item:hover { background: #fafbfd; }
.wl-item.on { background: rgba(224,32,32,.06); border-left: 3px solid var(--brand); padding-left: 11px; }
.wl-item .av { width: 36px; height: 36px; border-radius: 50%; background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; font-size: 14px; }
.wl-item .ct { flex: 1; min-width: 0; }
.wl-item .r1 { display: flex; align-items: center; gap: 6px; }
.wl-item .nm { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wl-item .tm { margin-left: auto; font-size: 11px; color: var(--ink-3); flex-shrink: 0; }
.wl-item .pv { font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.wl-item .bd { margin-left: auto; background: var(--brand); color: #fff; font-size: 11px; min-width: 17px; height: 17px; line-height: 17px; text-align: center; border-radius: 9px; padding: 0 5px; flex-shrink: 0; }
.wl-item .lv { font-size: 10px; padding: 0 5px; border-radius: 4px; }
.lv-A { background: rgba(224,32,32,.12); color: var(--brand); }
.lv-B { background: rgba(255,180,0,.16); color: #a97200; }
.lv-C { background: #eef1f6; color: var(--ink-3); }

.work-chat { flex: 1; min-width: 0; background: #fff; border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.wc-head { padding: 13px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.wc-head .nm { font-size: 16px; font-weight: 700; }
.wc-head .meta { font-size: 12px; color: var(--ink-3); }
.wc-head .act { margin-left: auto; display: flex; gap: 8px; }
.wc-msgs { flex: 1; overflow-y: auto; padding: 18px; background: #f7f8fa; display: flex; flex-direction: column; gap: 12px; }
.wc-msgs .row { display: flex; gap: 9px; align-items: flex-start; max-width: 78%; }
.wc-msgs .row.me { flex-direction: row-reverse; margin-left: auto; }
.wc-msgs .av { width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: 600; }
.wc-msgs .bb { padding: 9px 13px; border-radius: 12px; font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.wc-msgs .row.them .bb { background: #fff; box-shadow: 0 1px 6px rgba(20,26,40,.06); }
.wc-msgs .row.me .bb { background: var(--brand); color: #fff; }
.wc-msgs .row .tm { font-size: 11px; color: var(--ink-3); margin-top: 3px; }
.wc-msgs .row.me .tm { color: rgba(255,255,255,.75); }
.wc-msgs .sys { align-self: center; font-size: 12px; color: var(--ink-3); background: rgba(0,0,0,.05); padding: 3px 12px; border-radius: 999px; max-width: 90%; text-align: center; }

.wc-foot { border-top: 1px solid var(--line); padding: 8px 14px 10px; }
.wc-tabs { display: flex; gap: 14px; margin-bottom: 8px; }
.wc-tabs span { font-size: 12px; color: var(--ink-3); cursor: pointer; padding-bottom: 3px; border-bottom: 2px solid transparent; }
.wc-tabs span.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.wc-src { max-height: 130px; overflow-y: auto; font-size: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; background: #fafbfd; }
.wc-src div { padding: 3px 0; color: var(--ink-2); word-break: break-all; }
.wc-src div b { color: var(--ink-3); font-weight: 500; display: inline-block; width: 62px; }
.wc-quick { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; max-height: 62px; overflow-y: auto; }
.wc-quick .mat-item { font-size: 12px; background: var(--bg); border: 1px solid var(--line); color: var(--ink-2); padding: 3px 10px; border-radius: 999px; cursor: pointer; }
.wc-quick .mat-item:hover { border-color: var(--brand); color: var(--brand); }
.wc-quick .mat-item i { font-style: normal; opacity: .6; margin-right: 3px; }
.wc-input { display: flex; gap: 8px; align-items: flex-end; }
.wc-input textarea { flex: 1; border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px; font-size: 14px; font-family: inherit; resize: none; outline: none; min-height: 38px; max-height: 110px; line-height: 1.5; }
.wc-input textarea:focus { border-color: var(--brand); }
.wc-input button { height: 38px; padding: 0 20px; border: 0; border-radius: 9px; background: var(--brand); color: #fff; font-weight: 600; flex-shrink: 0; }

.work-side { width: 260px; flex-shrink: 0; background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: auto; }
.ws-h { padding: 13px 16px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 14px; }
.ws-b { padding: 14px 16px; }
.ws-line { display: flex; padding: 7px 0; font-size: 13px; border-bottom: 1px dashed var(--line); }
.ws-line:last-child { border-bottom: 0; }
.ws-line .k { color: var(--ink-3); width: 62px; flex-shrink: 0; }
.ws-line .v { flex: 1; word-break: break-all; }
.ws-b select, .ws-b input { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; font-size: 13px; font-family: inherit; outline: none; margin-bottom: 8px; }
.ws-b textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; font-family: inherit; outline: none; resize: vertical; min-height: 60px; margin-bottom: 8px; }
.ws-b select:focus, .ws-b input:focus, .ws-b textarea:focus { border-color: var(--brand); }

/* ---------- 弹窗 ---------- */
.mask { position: fixed; inset: 0; background: rgba(15,20,30,.45); display: none; align-items: center; justify-content: center; z-index: 900; }
.mask.on { display: flex; }
.modal { background: #fff; border-radius: 14px; width: 480px; max-width: 92vw; max-height: 88vh; overflow: auto; }
.modal .m-h { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal .m-h h3 { font-size: 16px; }
.modal .m-h .x { margin-left: auto; background: none; border: 0; font-size: 18px; color: var(--ink-3); }
.modal .m-b { padding: 18px 20px; }
.modal .m-f { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

.toast {
  position: fixed; left: 50%; top: 22px; transform: translateX(-50%); z-index: 2000;
  background: rgba(23,27,34,.92); color: #fff; padding: 10px 20px; border-radius: 10px; font-size: 14px;
  opacity: 0; transition: opacity .25s, top .25s; pointer-events: none;
}
.toast.on { opacity: 1; top: 32px; }

@media (max-width: 1100px) {
  .work-side { display: none; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  .sidebar { width: 62px; }
  .sidebar .sb-top b, .sidebar .sb-top small, .sidebar nav a span, .sb-user .nm, .sb-user .rl { display: none; }
  .sidebar nav a { justify-content: center; }
  .work-list { width: 220px; }
}

/* ============================================================
   嵌入模式：本页面被其他系统后台用 iframe 引入时（?embed=1）
   隐藏左侧导航，只保留「会话列表 + 聊天区」，铺满父容器
   ============================================================ */
body.embed { background: #fff; }
body.embed .app { min-height: 100vh; }
body.embed .sidebar { display: none !important; }
body.embed .main { width: 100%; }
body.embed .topbar-c { height: 50px; padding: 0 14px; }
body.embed .topbar-c h2 { font-size: 15px; }
body.embed .content { padding: 12px; }
body.embed .work { height: calc(100vh - 74px); gap: 10px; }
body.embed .work-list { width: 270px; }
body.embed .toast { top: 8px; }
@media (max-width: 900px) {
  body.embed .work-side { display: none; }
  body.embed .work-list { width: 220px; }
}

/* 代码片段展示框（后台「嵌入其他系统」用） */
.code-box {
  margin: 0; background: #0f172a; color: #e6edf7; border-radius: 10px; padding: 13px 15px;
  font-family: Consolas, "Courier New", monospace; font-size: 12.5px; line-height: 1.75;
  white-space: pre-wrap; word-break: break-all; overflow: auto; max-height: 200px;
}
