/* CardPlug 管理后台样式。零依赖，浅色/深色跟随系统。 */

:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-alt: #e9e9ee;
  --text: #000000;
  --text-secondary: rgba(60, 60, 67, 0.62);
  --text-tertiary: rgba(60, 60, 67, 0.36);
  --border: rgba(60, 60, 67, 0.18);
  --accent: #0a84ff;
  --success: #248a3d;
  --warning: #b26a00;
  --danger: #d70015;
  --warning-bg: rgba(255, 149, 0, 0.12);
  --danger-bg: rgba(255, 59, 48, 0.1);
  --success-bg: rgba(52, 199, 89, 0.14);
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-alt: #2c2c2e;
    --text: #ffffff;
    --text-secondary: rgba(235, 235, 245, 0.62);
    --text-tertiary: rgba(235, 235, 245, 0.32);
    --border: rgba(84, 84, 88, 0.6);
    --accent: #0a84ff;
    --success: #30d158;
    --warning: #ff9f0a;
    --danger: #ff453a;
    --warning-bg: rgba(255, 159, 10, 0.16);
    --danger-bg: rgba(255, 69, 58, 0.16);
    --success-bg: rgba(48, 209, 88, 0.16);
    --shadow: none;
  }
}

* { box-sizing: border-box; }

/*
 * 必须放在所有布局规则之前（或用 !important）。
 *
 * 原因：浏览器默认样式是 `[hidden] { display: none }`，但**作者样式里的 display
 * 优先级更高**。下面 .modal / .panel / .login-view 都设置了 display，
 * 如果不加这条，标了 hidden 的元素依然会显示出来
 * （典型症状：弹窗挡住页面、所有面板同时可见）。
 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--text-secondary); }
.small { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--danger); font-size: 13px; white-space: pre-line; }

/* 服务器连接状态指示 */
.status {
  font-style: normal;
  font-size: 12px;
  padding: 1px 7px;
  border-radius: 999px;
  margin-left: 4px;
}
.status.checking { background: var(--surface-alt); color: var(--text-tertiary); }
.status.ok { background: var(--success-bg); color: var(--success); }
.status.bad { background: var(--danger-bg); color: var(--danger); }

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

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 16px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow);
}

.login-brand { text-align: center; display: flex; flex-direction: column; gap: 6px; align-items: center; margin-bottom: 8px; }
.login-brand h1 { font-size: 20px; }

.logo {
  width: 52px; height: 52px; border-radius: 14px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-weight: 600; font-size: 18px; letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.logo.sm { width: 26px; height: 26px; border-radius: 7px; font-size: 11px; margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-secondary); }

input[type="email"], input[type="password"], input[type="text"], select, textarea {
  width: 100%;
  padding: 11px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface-alt);
  border: 1px solid transparent;
  border-radius: 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }

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

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  font-weight: 500;
  background: var(--surface-alt);
  color: var(--text);
  transition: opacity 0.12s;
}
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.block { width: 100%; padding: 12px; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.success { background: var(--success); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text-secondary); }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }

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

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }

.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tabs button {
  border: none; background: transparent; color: var(--text-secondary);
  padding: 8px 14px; border-radius: 9px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.tabs button:hover { background: var(--surface-alt); }
.tabs button.active { background: var(--accent); color: #fff; }

.badge {
  min-width: 20px; padding: 0 6px; height: 18px; line-height: 18px;
  border-radius: 9px; background: var(--danger); color: #fff;
  font-size: 11px; text-align: center; font-weight: 600;
}
.tabs button.active .badge { background: rgba(255, 255, 255, 0.28); }

.user { display: flex; align-items: center; gap: 10px; }

/* ---------- 内容区 ---------- */

main { padding: 24px; max-width: 1180px; margin: 0 auto; }
.panel { display: flex; flex-direction: column; gap: 14px; }

.section-head {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin-bottom: 2px;
}
.section-head h2 { font-size: 17px; }

/* 概览卡片 */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; }
.stat {
  background: var(--surface); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px;
}
.stat .value { font-size: 30px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .label { font-size: 13px; color: var(--text-secondary); }
.stat.warn .value { color: var(--warning); }
.stat.danger .value { color: var(--danger); }

/* 列表项 */
.item {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
}
.item-head { display: flex; align-items: flex-start; gap: 12px; }
.item-title { font-weight: 600; font-size: 15px; word-break: break-word; }
.item-sub { font-size: 13px; color: var(--text-secondary); }
.item-meta { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.chip.neutral { background: var(--surface-alt); color: var(--text-secondary); }
.chip.warn { background: var(--warning-bg); color: var(--warning); }
.chip.danger { background: var(--danger-bg); color: var(--danger); }
.chip.success { background: var(--success-bg); color: var(--success); }
.chip.accent { background: rgba(10, 132, 255, 0.14); color: var(--accent); }

.note {
  display: flex; gap: 8px; align-items: flex-start;
  background: var(--warning-bg); color: var(--warning);
  padding: 10px 12px; border-radius: 9px; font-size: 13px;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* 工单对话气泡 */
.thread { display: flex; flex-direction: column; gap: 8px; }
.bubble {
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  max-width: 92%;
  word-break: break-word;
}
.bubble.admin { background: rgba(10, 132, 255, 0.14); align-self: flex-end; }
.bubble-head { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }

/* 日志条目更紧凑 */
.item.compact { padding: 12px 16px; gap: 4px; }

.empty {
  background: var(--surface); border-radius: var(--radius);
  padding: 56px 24px; text-align: center;
  display: flex; flex-direction: column; gap: 6px;
  box-shadow: var(--shadow);
}

.loading { padding: 48px; text-align: center; color: var(--text-secondary); }

/* 卡片管理工具条 */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar select { width: auto; min-width: 160px; }
.toolbar .opt { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.toolbar .opt input { width: auto; }

/* 提示音音量滑块 */
.toolbar .opt input[type="range"] { width: 92px; accent-color: #0a84ff; cursor: pointer; }
.toolbar .opt input[type="range"]:disabled { opacity: .4; cursor: not-allowed; }
.toolbar .opt #opt-volume-label {
  min-width: 36px; text-align: right; font-variant-numeric: tabular-nums;
}

/* ---------- 品种编辑弹窗里的表单 ---------- */

.form-grid { display: grid; gap: 12px; margin: 14px 0; }

.form-grid .field { display: flex; flex-direction: column; gap: 5px; }
.form-grid .field > span { font-size: 13px; color: var(--text-secondary); }

.form-grid .field input:not([type="checkbox"]) {
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}

.form-grid .field.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.form-grid .field.checkbox > span { font-size: 14px; color: var(--text); }
.form-grid .field.checkbox input { width: auto; }

/* Logo 选择：左边预览，右边按钮 */
.logo-picker { display: flex; align-items: center; gap: 12px; }
.logo-preview {
  width: 64px;
  height: 64px;
  flex: none;
  border: 1px dashed var(--border);
  border-radius: 12px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--surface-alt);
}
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }
.logo-actions { display: flex; flex-direction: column; gap: 6px; }

/* 列表里的 Logo（没有 logo 时回退成 icon + tint 的圆形色块） */
.cat-logo {
  width: 40px; height: 40px; border-radius: 10px; flex: none;
  display: grid; place-items: center; overflow: hidden;
  background: var(--surface-alt);
}
.cat-logo img { width: 100%; height: 100%; object-fit: contain; }

/* 品种列表每行 */
.cat-change { font-size: 12px; font-weight: 600; }
.cat-change.up { color: var(--danger); }    /* 涨 = 红 */
.cat-change.down { color: var(--success); } /* 跌 = 绿 */

/* ---------- 成交明细 ---------- */

.deal-detail {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px 20px;
}

.deal-row { display: flex; gap: 10px; align-items: baseline; }

.deal-row dt {
  flex: 0 0 64px;
  font-size: 13px;
  color: var(--text-secondary);
}

.deal-row dd {
  margin: 0;
  font-size: 13px;
  word-break: break-all;
}

/* 卡密：等宽字体 + 可整段选中，方便复制 */
.deal-code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  background: var(--surface-alt);
  border-radius: 6px;
  padding: 2px 8px;
  user-select: all;
}

.deal-thumb {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  text-decoration: none;
  width: fit-content;
}

.deal-thumb img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* 成交页的状态标签（待付 / 已付 / 异常） */
.tabs-inline { display: flex; gap: 4px; }
.tabs-inline button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 4px 14px;
  font-size: 13px;
  cursor: pointer;
}
.tabs-inline button:hover { border-color: var(--accent); color: var(--accent); }
.tabs-inline button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* 成交项底部的操作行：联系客户 + 改状态 */
.deal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* 积分充值：每笔成交都有，待付 / 已付 / 异常三个标签通用 */
.deal-points {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
}
.deal-points-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.deal-points-title { font-size: 13px; font-weight: 600; }
.deal-points-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.deal-points-row input {
  width: 130px;
  height: 32px;
  padding: 0 10px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}
.deal-points-row input:focus { border-color: var(--accent); }
/* 数字输入框的上下箭头在窄格子里很挤，去掉 */
.deal-points-row input::-webkit-outer-spin-button,
.deal-points-row input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.deal-points-row input[type="number"] { -moz-appearance: textfield; }

/* ---------- 汇率页 ---------- */

/* 阶梯：每条一个胶囊，一行放不下就换行 */
.tier-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tier-chip {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* 弹窗里的阶梯编辑器：一行 = 起始余额 + 费率 + 删除 */
.tier-editor { margin: 6px 0 4px; }
.tier-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
}
.tier-edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.tier-edit-row input {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}
.tier-edit-row input:focus { border-color: var(--accent); }
.tier-edit-row input[type='number']::-webkit-outer-spin-button,
.tier-edit-row input[type='number']::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

/* ---------- 弹窗 / 提示 ---------- */

.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.4);
  display: grid; place-items: center; padding: 24px;
}
.modal-card {
  background: var(--surface); border-radius: 14px;
  padding: 22px; width: 100%; max-width: 420px;
  display: flex; flex-direction: column; gap: 10px;
}
.modal-card h2 { font-size: 17px; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  z-index: 200; padding: 11px 20px; border-radius: 10px;
  background: #1c1c1e; color: #fff; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  max-width: 90vw; text-align: center;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---------- 实时客服：会话列表 ---------- */

.conv {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 12px;
  align-items: flex-start;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.conv:hover { background: var(--surface-alt); }
.conv.unread { border-left-color: var(--danger); }
.conv.active { border-left-color: var(--accent); }

.conv-avatar {
  width: 40px; height: 40px; border-radius: 20px;
  background: var(--surface-alt); color: var(--text-secondary);
  display: grid; place-items: center; font-weight: 600; flex: none;
}
.conv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.conv-row { display: flex; align-items: center; gap: 8px; }
.conv-name { font-weight: 600; font-size: 15px; }
.conv-preview {
  font-size: 13px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* 搜索结果：命中的聊天内容用主色加粗，一眼看出「为什么这条被搜到」 */
.conv-preview.hit { color: var(--accent); font-weight: 600; }

/* ---------- 「客服会话」页标题右侧的搜索框 ---------- */
.conv-search {
  display: flex; align-items: center; gap: 6px;
  flex: 0 1 240px; width: 240px;
  margin-left: 12px; align-self: center;
}
.conv-search input[type="search"] {
  flex: 1; min-width: 0;
  padding: 6px 10px; font-size: 13px;
}
.conv-search-btn {
  flex: none; padding: 6px 12px; font-size: 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.conv-search-btn:hover { border-color: var(--accent); color: var(--accent); }
.conv-search-clear {
  flex: none; width: 26px; height: 26px; line-height: 1;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text-secondary); cursor: pointer;
}
.conv-search-clear:hover { border-color: var(--danger); color: var(--danger); }
.conv-time { font-size: 12px; color: var(--text-tertiary); flex: none; }
.conv-count {
  min-width: 20px; height: 20px; line-height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 600; text-align: center; flex: none;
}

/* ---------- 浮动客服窗口（可拖动 / 可最小化） ---------- */

.chat-window {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 980px;
  height: 660px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  display: flex;
  flex-direction: row; /* 三栏：客户列表 + 当前会话 + 客户资料 */
  overflow: hidden;
  /* 右下角可拖拽缩放。resize 只在 overflow 非 visible 时生效，
     所以上面那个 overflow: hidden 不能删。 */
  resize: both;
  /* 三栏最窄也要 820：左 220 + 中 300 + 右 300 */
  min-width: 820px;
  min-height: 420px;
  max-width: 96vw;
  max-height: 92vh;
  z-index: 150;
}
.chat-window.pinned { z-index: 300; }

/* 最小化：只剩一条标题栏。左右两栏也一起收起，未读数显示在标题上 */
.chat-window.minimized { height: 54px; min-height: 54px; resize: none; }
.chat-window.minimized .chat-side,
.chat-window.minimized .chat-aside,
.chat-window.minimized .chat-body,
.chat-window.minimized .chat-form,
.chat-window.minimized .chat-rating-toolbar { display: none; }
.chat-window.minimized .chat-points { display: none; }
.chat-window.minimized .chat-main { flex: 1; }

/* ---------- 左栏：多客户列表 ---------- */

.chat-side {
  width: 220px;
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--surface-alt);
}

.chat-side-head {
  flex: none;
  padding: 9px 12px;
  background: var(--accent);
  color: #fff;
  cursor: grab;
  user-select: none;
}
.chat-side-head:active { cursor: grabbing; }
.chat-side-title { font-weight: 600; font-size: 13px; }

/* 搜索表单 */
.chat-search-form {
  display: flex; align-items: center; gap: 4px;
  margin-top: 7px;
}
.chat-search-form input[type="search"] {
  flex: 1;
  border: none; border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  outline: none;
}
.chat-search-form input[type="search"]::-webkit-search-cancel-button { display: none; }
.chat-search-form button[type="submit"],
#chat-search-clear {
  flex: none;
  width: 26px; height: 26px;
  border: none; border-radius: 6px;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: grid; place-items: center;
}
.chat-search-form button[type="submit"]:hover,
#chat-search-clear:hover { background: rgba(255, 255, 255, 0.38); }

.chat-side-list { flex: 1; overflow-y: auto; min-height: 0; }
.chat-side-empty {
  padding: 28px 12px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1.6;
}

.chat-side-item {
  position: relative;
  padding: 10px 12px 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.chat-side-item:hover { background: var(--surface); }
.chat-side-item.active { background: var(--surface); }
/* 选中态：左侧一条蓝条 */
.chat-side-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
}

.chat-side-row1 { display: flex; align-items: center; gap: 6px; }
.chat-side-name {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-side-badge {
  flex: none;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: grid;
  place-items: center;
}

.chat-side-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-side-ratings { display: flex; align-items: center; gap: 10px; font-size: 11px; font-weight: 600; }
.chat-side-rating-check { color: var(--success); }
.chat-side-rating-x { color: var(--danger); }

.chat-side-row3 {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-tertiary);
}
/* 同一客户合并了几个会话 */
.chat-side-threads {
  margin-left: auto;
  padding: 0 5px;
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--text-secondary);
  font-size: 10px;
  white-space: nowrap;
}

/* 搜索匹配项高亮 */
.chat-side-item.chat-side-search-match .chat-side-preview {
  color: var(--accent);
  font-weight: 600;
}

/* ---------- 右栏：当前会话 ---------- */

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px;
  background: var(--accent); color: #fff;
  cursor: grab; user-select: none; flex: none;
}
.chat-head:active { cursor: grabbing; }
.chat-title { font-weight: 600; font-size: 14px; }
.chat-sub { font-size: 11px; opacity: 0.85; margin-top: 2px; }
.chat-head-actions { display: flex; gap: 4px; }
.chat-icon {
  width: 26px; height: 26px; border: none; border-radius: 7px;
  background: rgba(255, 255, 255, 0.18); color: #fff;
  font-size: 15px; line-height: 1; display: grid; place-items: center;
}
.chat-icon:hover { background: rgba(255, 255, 255, 0.32); }
.chat-icon[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.42);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

/* ---------- 右栏：客户资料 ---------- */

.chat-aside {
  width: 300px;
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--surface-alt);
}
.chat-aside-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  /* 和另外两个标题栏一样，能拖着整个窗口移动 */
  cursor: grab;
  user-select: none;
}
.chat-aside-head:active { cursor: grabbing; }
.chat-aside-uid {
  font-size: 10px;
  font-weight: 400;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 只有这一层滚动；下面的 #chat-profile-body 会被整块重绘 */
.chat-profile {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 12px;
}
.chat-profile-body { display: flex; flex-direction: column; gap: 10px; }
.chat-profile-empty {
  padding: 24px 4px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1.6;
}

.chat-profile-section { padding-bottom: 8px; border-bottom: 1px dashed var(--border); }
.chat-profile-section:last-child { padding-bottom: 0; border-bottom: 0; }
.chat-profile-h {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
}
.chat-profile-list { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.chat-profile-row {
  display: grid;
  grid-template-columns: 60px minmax(0, 1fr);
  gap: 8px;
  font-size: 12px;
  line-height: 1.5;
}
.chat-profile-row dt { color: var(--text-tertiary); }
.chat-profile-row dd { margin: 0; color: var(--text); word-break: break-all; }

/* 三个积分 KPI */
.chat-profile-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}
.chat-kpi {
  padding: 5px 4px;
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
}
.chat-kpi b {
  display: block;
  font-size: 15px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.chat-kpi span { font-size: 10px; color: var(--text-tertiary); }

.chat-profile-rating { display: flex; gap: 12px; font-size: 13px; font-weight: 700; }
.chat-profile-check { color: var(--success); }
.chat-profile-x { color: var(--danger); }

.chat-profile-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-tag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface);
  color: var(--text-secondary);
}
.chat-tag.admin { background: var(--success-bg); color: var(--accent); }
.chat-tag.ok { background: var(--success-bg); color: var(--success); }
.chat-tag.banned { background: var(--danger-bg); color: var(--danger); }
.chat-profile-ban {
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--danger);
  word-break: break-word;
}

/* 右栏底部：积分 + 评价（固定在底部，不随资料滚动） */
.chat-aside-foot {
  flex: none;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.chat-aside-foot .chat-points { border-top: 0; }

.chat-body {
  flex: 1; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.chat-empty { margin: auto; color: var(--text-tertiary); font-size: 13px; text-align: center; }

.msg {
  max-width: 78%; padding: 8px 12px; border-radius: 12px;
  font-size: 14px; line-height: 1.5;
  word-break: break-word; white-space: pre-wrap;
}
.msg.agent { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.user { align-self: flex-start; background: var(--surface-alt); color: var(--text); border-bottom-left-radius: 4px; }
.msg-time { font-size: 11px; opacity: 0.7; margin-top: 4px; }

/* 客户消息的中文翻译：和原文用一条细线隔开，字号小一点、颜色淡一点，
   让人一眼看出「上面是原文，下面是译文」，不会混淆。 */
.msg-tr {
  margin-top: 6px; padding-top: 6px;
  border-top: 1px dashed currentColor;
  font-size: 13px; opacity: 0.78;
}
.msg-tr-lang {
  margin-left: 6px; padding: 0 4px;
  border: 1px solid currentColor; border-radius: 3px;
  font-size: 10px; text-transform: uppercase; opacity: 0.7;
  vertical-align: middle;
}

/* 搜索命中消息：短暂高亮，帮助定位 */
.msg.chat-search-hit {
  animation: chat-search-flash 3.5s ease-out;
}
@keyframes chat-search-flash {
  0%   { box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.55); }
  60%  { box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25); }
  100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}

.chat-form {
  display: flex; gap: 8px; padding: 10px;
  border-top: 1px solid var(--border); flex: none; align-items: flex-end;
}
.chat-form textarea { flex: 1; resize: none; max-height: 100px; padding: 9px 10px; font-size: 14px; }

/* ---------- 积分充值（「客户累计」上方） ---------- */
.chat-points {
  flex: none;
  padding: 8px 10px 6px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.chat-points-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
/* 标题行右侧：当前积分 · 累计充值（数字放大加粗，客服要一眼看到） */
.chat-points-balance {
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-points-balance b {
  margin: 0 2px;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.chat-points-row { display: flex; align-items: center; gap: 8px; }
.chat-points-row input {
  flex: 1 1 0;
  width: 100%;
  min-width: 0;
  padding: 7px 10px;
  font-size: 13px;
  border-radius: 8px;
  background: var(--surface-alt);
  border: 1px solid transparent;
  color: var(--text);
  outline: none;
}
.chat-points-row input:focus { border-color: var(--accent); }
.chat-points-add {
  flex: none;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.chat-points-add:hover:not(:disabled) { filter: brightness(1.06); }
/* 扣减：与「充值」并排的实体按钮，不用小号文字链接 —— 太容易看不见 */
.chat-points-sub {
  flex: none;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: var(--surface);
  color: var(--danger);
  cursor: pointer;
}
.chat-points-sub:hover:not(:disabled) { background: var(--danger); color: #fff; }
.chat-points-add:disabled,
.chat-points-sub:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-points-hint { margin-top: 5px; font-size: 11px; color: var(--accent); }
.chat-points-hint[hidden] { display: none; }

.chat-rating-toolbar {
  flex: none;
  padding: 7px 10px 9px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.chat-rating-summary { margin-bottom: 6px; color: var(--text-secondary); font-size: 11px; }
.chat-rating-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.chat-rating-action {
  min-width: 0;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.chat-rating-action span { font-size: 14px; line-height: 1; }
.chat-rating-action small { font-size: 10px; font-weight: 600; }
.chat-rating-action.check { color: var(--success); }
.chat-rating-action.x { color: var(--danger); }
.chat-rating-action:hover:not(:disabled) { border-color: currentColor; filter: brightness(0.96); }
.chat-rating-action:disabled { opacity: 0.45; cursor: not-allowed; }

/* 窄屏塞不下 720px 的两栏：左栏收起，窗口铺满。
   想看完整客户列表可以去「客服会话」标签页。 */
/* 窄屏塞不下三栏：只收起左栏，客户资料栏始终保留（客服最常看的就是它） */
@media (max-width: 900px) {
  .chat-window { left: 12px; right: 12px; width: auto; min-width: 0; }
  .chat-side { display: none; }
  .chat-aside { width: 260px; }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  main { padding: 14px; }
  .brand span:not(.logo) { display: none; }
}

/* ---- 聊天窗口：图片消息 ---- */
.msg-image {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: zoom-in;
}
.msg-image-only { margin-bottom: 0; }

/* 输入区的发图按钮 */
.chat-image-btn {
  width: 34px; height: 34px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text-secondary);
  cursor: pointer; font-size: 16px;
}
.chat-image-btn:hover { background: var(--surface-alt); }
.chat-image-btn:disabled { opacity: 0.45; cursor: default; }

/* ---- 聊天窗口：独立弹出模式 ---- */
/* 用 ?chat=popup 打开时，只显示可独立缩放的聊天窗 */
body.chat-popup > *:not(#chat-window) { display: none !important; }
body.chat-popup { overflow: hidden; }
body.chat-popup #chat-window {
  position: fixed;
  width: 980px;
  height: 660px;
  min-width: 820px;
  min-height: 420px;
  right: 12px;
  bottom: 12px;
  max-width: 96vw;
  max-height: 92vh;
  border: 0;
  border-radius: 10px;
  box-shadow: none;
  resize: both;
}

/* 拖动窗口时不要选中文字 */
.chat-window.dragging { user-select: none; }
