/* 客服系统 - 控制台 / 管理后台 共用样式 */
:root {
  --kf-blue: #3B82F6;
  --kf-blue-d: #2563eb;
  --kf-bg: #f6f7fb;
  --kf-card: #fff;
  --kf-border: #e8eaf0;
  --kf-text: #1f2430;
  --kf-muted: #8b93a1;
  --kf-red: #ef4444;
  --kf-green: #10b981;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--kf-text);
  background: var(--kf-bg);
}

button, input, textarea, select { font-family: inherit; font-size: 14px; color: inherit; }
button { cursor: pointer; }
a { color: var(--kf-blue); text-decoration: none; }

/* ---------------------------------------------------------------- 登录页 */
.login-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--kf-card); border-radius: 16px; padding: 28px 24px; box-shadow: 0 8px 32px rgba(0,0,0,.08); }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p.sub { color: var(--kf-muted); font-size: 13px; margin-bottom: 22px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: #5b6270; margin-bottom: 6px; }
.field input { width: 100%; padding: 11px 12px; border: 1px solid var(--kf-border); border-radius: 10px; outline: none; background: #fff; }
.field input:focus { border-color: var(--kf-blue); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 10px; border: none; background: var(--kf-blue); color: #fff; font-weight: 600; }
.btn:hover { background: var(--kf-blue-d); }
.btn-block { width: 100%; padding: 12px; }
.btn-ghost { background: #fff; border: 1px solid var(--kf-border); color: var(--kf-text); }
.btn-ghost:hover { background: #f2f4f8; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-danger { background: var(--kf-red); }
.btn-danger:hover { background: #dc2626; }
.alert { padding: 10px 12px; border-radius: 10px; background: #fef2f2; color: #b91c1c; font-size: 13px; margin-bottom: 14px; display: none; }
.alert.show { display: block; }

/* ------------------------------------------------------------------ 框架 */
.topbar { height: 56px; background: #fff; border-bottom: 1px solid var(--kf-border); display: flex; align-items: center; gap: 12px; padding: 0 14px; position: sticky; top: 0; z-index: 20; }
.topbar .brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
.topbar .grow { flex: 1; }
.topbar .who { font-size: 13px; color: var(--kf-muted); white-space: nowrap; }
.navlink { padding: 6px 12px; border-radius: 8px; color: #5b6270; font-size: 13px; font-weight: 600; }
.navlink.active { background: #eef4ff; color: var(--kf-blue); }

.stats { display: flex; gap: 8px; overflow-x: auto; padding: 10px 14px 0; }
.stat { flex: 0 0 auto; background: #fff; border: 1px solid var(--kf-border); border-radius: 12px; padding: 8px 14px; min-width: 88px; }
.stat .n { font-size: 18px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--kf-muted); }
.stat.alerting .n { color: var(--kf-red); }

.filters { display: flex; gap: 8px; padding: 10px 14px; align-items: center; overflow-x: auto; }
.filters > * { flex: 0 0 auto; }   /* 不加会被 flex 压缩，导致“只看我的”文字竖排 */
.filters select, .filters input { padding: 7px 10px; border: 1px solid var(--kf-border); border-radius: 9px; background: #fff; outline: none; }
.filters input { min-width: 140px; flex: 1 1 auto; }
.chip { white-space: nowrap; }

.layout { display: flex; gap: 12px; padding: 0 14px 14px; align-items: stretch; height: calc(100vh - 56px - 62px - 56px); min-height: 420px; }
.pane { background: var(--kf-card); border: 1px solid var(--kf-border); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; }
.sidebar { width: 340px; flex: 0 0 340px; }
.main { flex: 1; min-width: 0; }

/* ---------------------------------------------------------- 会话列表 */
.conv-list { overflow-y: auto; flex: 1; }
.conv { padding: 12px 14px; border-bottom: 1px solid #f1f3f7; cursor: pointer; display: flex; gap: 10px; }
.conv:hover { background: #fafbfe; }
.conv.active { background: #eef4ff; }
.conv .avatar { width: 38px; height: 38px; border-radius: 50%; background: #e6e9ef; color: #6b7280; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.conv .mid { flex: 1; min-width: 0; }
.conv .line1 { display: flex; align-items: center; gap: 6px; }
.conv .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .time { font-size: 11px; color: var(--kf-muted); margin-left: auto; white-space: nowrap; }
.conv .preview { font-size: 13px; color: var(--kf-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv .meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: #f1f3f7; color: #6b7280; white-space: nowrap; }
.tag.site { background: #eef4ff; color: var(--kf-blue); }
.tag.user { background: #ecfdf5; color: #047857; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.tag.unassigned { background: #fff7ed; color: #c2410c; }
.unread { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--kf-red); color: #fff; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

/* -------------------------------------------------------------- 聊天区 */
.chat-head { padding: 10px 14px; border-bottom: 1px solid var(--kf-border); display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.chat-head .info { flex: 1; min-width: 0; }
.chat-head .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .s { font-size: 12px; color: var(--kf-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .page { font-size: 12px; }
.chat-head .page a { color: var(--kf-blue); text-decoration: underline; }
.back-btn { display: none; }

.chat-body { flex: 1; overflow-y: auto; padding: 14px; background: #f8f9fc; -webkit-overflow-scrolling: touch; }
/* 气泡排版不用 flex：flex 子项宽度受 min-content 影响（中文 min-content 只有 1 个字），
   叠加百分比 max-width 的循环依赖会把气泡压成 1 个字宽。用 inline-block 收缩包裹更可靠。 */
.row { margin-bottom: 12px; }
.row.visitor { text-align: left; }
.row.agent { text-align: right; }
.row.system { text-align: center; }
.row .item { display: inline-block; max-width: 78%; text-align: left; vertical-align: top; }
.row.system .item { max-width: 92%; }
.msg { padding: 9px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: break-word; word-break: normal; font-size: 14px; }
.row.visitor .msg { background: #fff; border-bottom-left-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.row.agent .msg { background: var(--kf-blue); color: #fff; border-bottom-right-radius: 4px; }
.row.system .msg { background: transparent; color: var(--kf-muted); font-size: 12px; padding: 4px; }
.msg img { max-width: 220px; border-radius: 8px; display: block; cursor: zoom-in; }
.msg .who { font-size: 11px; opacity: .75; margin-bottom: 3px; }
.mtime { font-size: 11px; color: #b6bcc8; margin-top: 4px; }
.row.agent .mtime { text-align: right; }

.composer { border-top: 1px solid var(--kf-border); padding: 10px 12px; background: #fff; flex-shrink: 0; position: relative; }
.composer textarea { width: 100%; border: none; outline: none; resize: none; max-height: 100px; min-height: 24px; line-height: 1.5; background: transparent; }
.composer .actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

/* 常用语弹层 */
.quick-panel { display: none; position: absolute; left: 10px; right: 10px; bottom: calc(100% - 4px); max-height: 320px; overflow-y: auto; background: #fff; border: 1px solid var(--kf-border); border-radius: 12px; box-shadow: 0 -6px 28px rgba(15,23,42,.14); z-index: 5; }
.quick-panel.open { display: block; }
.quick-item { padding: 10px 14px; border-bottom: 1px solid #f1f3f7; cursor: pointer; }
.quick-item:last-child { border-bottom: none; }
.quick-item:hover { background: #f7f9ff; }
.quick-title { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.quick-content { font-size: 12px; color: var(--kf-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quick-empty { padding: 18px 14px; text-align: center; color: var(--kf-muted); font-size: 13px; }
.iconbtn { width: 34px; height: 34px; border-radius: 9px; border: none; background: #f1f3f7; color: #6b7280; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.iconbtn:hover { background: #e6e9ef; }
.iconbtn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.spacer { flex: 1; }
.typing { height: 18px; padding: 0 14px; font-size: 12px; color: var(--kf-muted); }

.placeholder { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--kf-muted); font-size: 13px; }

/* ------------------------------------------------------------ 管理后台 */
.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 14px; }
.card { background: #fff; border: 1px solid var(--kf-border); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin-bottom: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
table th, table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid #f1f3f7; vertical-align: middle; }
table th { color: var(--kf-muted); font-weight: 600; font-size: 12px; }
code.key { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; background: #f5f6fa; padding: 2px 6px; border-radius: 6px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--kf-border); border-radius: 999px; font-size: 13px; cursor: pointer; background: #fff; }
.chip input { margin: 0; }
.chip.on { border-color: var(--kf-blue); background: #eef4ff; color: var(--kf-blue); }
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal-mask.open { display: flex; }
.modal { background: #fff; border-radius: 16px; padding: 20px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; }
.modal h3 { font-size: 16px; margin-bottom: 14px; }
.modal .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.toast { position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%); background: #1f2430; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13px; opacity: 0; transition: opacity .2s; z-index: 100; pointer-events: none; }
.toast.show { opacity: .95; }

.empty { padding: 40px 16px; text-align: center; color: var(--kf-muted); font-size: 13px; }

/* ---------------------------------------------------------------- 响应式 */
@media (max-width: 768px) {
  .layout { height: calc(100vh - 56px - 58px - 56px); padding: 0 8px 8px; gap: 0; }
  .pane { border-radius: 12px; }
  .sidebar { flex: 1 1 auto; width: auto; }
  .main { display: none; }
  body.chat-open .sidebar { display: none; }
  body.chat-open .main { display: flex; }
  .back-btn { display: flex; }
  .filters { padding: 8px; flex-wrap: wrap; overflow-x: visible; }
  .filters input { flex: 1 1 100%; min-width: 0; }
  .stats { padding: 8px 8px 0; }
  .grid2 { grid-template-columns: 1fr; }
  .topbar .who { display: none; }
}

/* ------------------------------------------------------- 会话归属提示条 */
.assignee-bar{
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; font-size: 13px; flex-shrink: 0;
  background: #fff7ed; color: #c2410c; border-bottom: 1px solid #fed7aa;
}
.assignee-bar.assignee-bar-taken{ background: #eff6ff; color: #1d4ed8; border-bottom-color: #bfdbfe; }
.assignee-bar .assignee-text{ flex: 1; }
.assignee-bar .btn{ padding: 4px 10px; font-size: 12px; border-radius: 8px; }
