* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 14px; color: #333; background: #f0f2f5; }
[hidden] { display: none !important; }
a { color: #1677ff; text-decoration: none; }
input, select, textarea, button { font-family: inherit; font-size: 14px; }
input, select, textarea { border: 1px solid #d9d9d9; border-radius: 6px; padding: 7px 10px; outline: none; background: #fff; }
input:focus, select:focus, textarea:focus { border-color: #1677ff; }
.muted { color: #999; }
.small { font-size: 12px; }

.btn { border: 1px solid #d9d9d9; background: #fff; color: #333; border-radius: 6px; padding: 6px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #1677ff; color: #1677ff; }
.btn.primary { background: #1677ff; border-color: #1677ff; color: #fff; }
.btn.primary:hover { background: #4096ff; }
.btn.danger { color: #ff4d4f; border-color: #ffccc7; }
.btn.danger:hover { background: #fff1f0; }
.btn.sm { padding: 3px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 登录 */
.login-view { height: 100%; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1677ff, #69b1ff); }
.login-box { width: 340px; background: #fff; padding: 36px 32px; border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.15); display: flex; flex-direction: column; gap: 14px; }
.login-box h1 { margin: 0; font-size: 22px; text-align: center; }
.login-box p { margin: -6px 0 6px; text-align: center; }
.login-box input { padding: 10px 12px; }
.login-box button { padding: 10px; font-size: 15px; }

/* 布局 */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { height: 54px; background: #001529; color: #fff; display: flex; align-items: center; padding: 0 18px; gap: 20px; flex-shrink: 0; }
.logo { font-size: 16px; font-weight: 600; white-space: nowrap; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.nav a { color: rgba(255,255,255,.7); padding: 8px 14px; border-radius: 6px; white-space: nowrap; position: relative; }
.nav a:hover { color: #fff; }
.nav a.active { color: #fff; background: #1677ff; }
.nav .dot-num { position: absolute; top: 0; right: 0; background: #ff4d4f; color: #fff; font-size: 11px; border-radius: 8px; padding: 0 5px; line-height: 16px; }
.me { display: flex; align-items: center; gap: 14px; white-space: nowrap; }
.me select { padding: 4px 6px; background: #0a2540; color: #fff; border-color: #234; }
.me a { color: rgba(255,255,255,.75); }
.me a:hover { color: #fff; }
.tab { flex: 1; min-height: 0; }

/* 工作台 */
.work { display: flex; }
.conv-side { width: 290px; background: #fff; border-right: 1px solid #eee; display: flex; flex-direction: column; flex-shrink: 0; }
.seg { display: flex; padding: 10px; gap: 6px; border-bottom: 1px solid #f0f0f0; }
.seg a { flex: 1; text-align: center; padding: 6px 0; border-radius: 6px; color: #666; background: #f5f5f5; font-size: 13px; }
.seg a.active { background: #1677ff; color: #fff; }
.conv-list { flex: 1; overflow-y: auto; }
.conv-item { padding: 12px 14px; border-bottom: 1px solid #f5f5f5; cursor: pointer; display: flex; gap: 10px; }
.conv-item:hover { background: #fafafa; }
.conv-item.active { background: #e6f4ff; }
.conv-item .avatar { width: 38px; height: 38px; border-radius: 50%; background: #91caff; color: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0; position: relative; }
.conv-item .avatar.on::after { content: ''; position: absolute; right: 0; bottom: 0; width: 10px; height: 10px; border-radius: 50%; background: #52c41a; border: 2px solid #fff; }
.conv-item .main { flex: 1; min-width: 0; }
.conv-item .line1 { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.conv-item .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .time { font-size: 12px; color: #aaa; flex-shrink: 0; }
.conv-item .line2 { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; gap: 6px; }
.conv-item .preview { font-size: 12px; color: #999; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: #ff4d4f; color: #fff; font-size: 11px; border-radius: 9px; padding: 0 6px; line-height: 18px; min-width: 18px; text-align: center; flex-shrink: 0; }
.list-empty { padding: 40px 0; text-align: center; color: #bbb; }

.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 4px; background: #f0f0f0; color: #666; font-weight: normal; }
.tag.waiting { background: #fff7e6; color: #fa8c16; }
.tag.active { background: #e6f4ff; color: #1677ff; }
.tag.closed { background: #f5f5f5; color: #999; }
.tag.on { background: #f6ffed; color: #52c41a; }
.tag.admin { background: #f9f0ff; color: #722ed1; }

.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: #f5f6f8; }
.empty { margin: auto; color: #bbb; font-size: 15px; }
.chat-box { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head { background: #fff; padding: 10px 18px; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.chat-head b { font-size: 16px; }
.chat-actions { display: flex; gap: 8px; }
.msgs { flex: 1; overflow-y: auto; padding: 16px 20px; }
.chat-input { background: #fff; border-top: 1px solid #eee; padding: 8px 14px 12px; position: relative; }
.chat-input.disabled textarea { background: #f5f5f5; }
.tools { display: flex; gap: 14px; padding-bottom: 6px; position: relative; }
.tool { cursor: pointer; color: #666; font-size: 13px; user-select: none; }
.tool:hover { color: #1677ff; }
.chat-input textarea { width: 100%; height: 80px; resize: none; border: 0; padding: 4px 0; }
.send-row { display: flex; justify-content: space-between; align-items: center; }
.quick-pop { position: absolute; bottom: 30px; left: 60px; width: 360px; max-height: 260px; overflow-y: auto; background: #fff; border: 1px solid #eee; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.12); z-index: 5; }
.quick-pop div { padding: 9px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid #f5f5f5; }
.quick-pop div:hover { background: #f0f7ff; }

/* 消息气泡 */
.msg { display: flex; margin: 12px 0; gap: 8px; }
.msg .body { max-width: 70%; display: flex; flex-direction: column; }
.msg .name { font-size: 12px; color: #999; margin-bottom: 3px; }
.msg .bubble { padding: 9px 13px; border-radius: 10px; line-height: 1.6; word-break: break-word; white-space: pre-wrap; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.msg .bubble.img { padding: 4px; }
.msg .bubble img { display: block; max-width: 240px; max-height: 260px; border-radius: 6px; cursor: zoom-in; }
.msg .av { width: 34px; height: 34px; border-radius: 50%; background: #91caff; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.msg.agent { flex-direction: row-reverse; }
.msg.agent .body { align-items: flex-end; }
.msg.agent .av { background: #1677ff; }
.msg.agent .bubble { background: #1677ff; color: #fff; }
.msg.agent .bubble.img { background: #fff; }
.msg .read { font-size: 11px; color: #bbb; margin-top: 2px; }
.sys { text-align: center; margin: 12px 0; }
.sys span { font-size: 12px; color: #888; background: #e8e9ec; padding: 4px 10px; border-radius: 10px; display: inline-block; max-width: 80%; }
.time-line { text-align: center; font-size: 12px; color: #bbb; margin: 16px 0 6px; }

/* 访客信息 */
.info-side { width: 280px; background: #fff; border-left: 1px solid #eee; overflow-y: auto; padding: 16px; flex-shrink: 0; }
.info-side h4 { margin: 18px 0 10px; font-size: 14px; }
.info-side h4:first-child { margin-top: 0; }
.info-side label { display: block; font-size: 12px; color: #999; margin: 8px 0 3px; }
.info-side input, .info-side textarea { width: 100%; }
.info-side textarea { height: 60px; resize: vertical; }
.kv { font-size: 12px; line-height: 1.6; margin-bottom: 8px; word-break: break-all; }
.kv span { color: #999; display: block; }
.hist-item { font-size: 12px; padding: 7px 8px; border-radius: 6px; background: #fafafa; margin-bottom: 6px; cursor: pointer; display: flex; justify-content: space-between; }
.hist-item:hover { background: #f0f7ff; }

/* 普通页面 */
.page { overflow-y: auto; padding: 20px 24px; }
.card { background: #fff; border-radius: 10px; padding: 20px 22px; margin-bottom: 18px; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.card h3 { margin: 0 0 16px; font-size: 16px; display: flex; justify-content: space-between; align-items: center; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 10px 10px; border-bottom: 1px solid #f0f0f0; font-size: 13px; }
.tbl th { background: #fafafa; color: #666; font-weight: 500; }
.tbl tr:hover td { background: #fcfcfc; }
.tbl .ops { display: flex; gap: 6px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border-radius: 10px; padding: 18px 20px; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.stat .num { font-size: 28px; font-weight: 600; margin-top: 6px; color: #1677ff; }
.form-row { display: flex; margin-bottom: 16px; align-items: flex-start; }
.form-row > label { width: 140px; flex-shrink: 0; padding-top: 7px; color: #555; }
.form-row .ctl { flex: 1; max-width: 560px; }
.form-row .ctl input[type=text], .form-row .ctl textarea, .form-row .ctl select { width: 100%; }
.form-row .ctl textarea { height: 70px; resize: vertical; }
.form-row .hint { font-size: 12px; color: #999; margin-top: 4px; }
pre.code { background: #1e1e1e; color: #d4d4d4; padding: 14px 16px; border-radius: 8px; overflow-x: auto; font-size: 13px; line-height: 1.6; white-space: pre-wrap; word-break: break-all; }
.steps { line-height: 2; color: #555; padding-left: 20px; }

/* 弹窗 */
.mask { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: #fff; border-radius: 10px; width: 460px; max-width: 94vw; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal.wide { width: 720px; }
.modal-head { padding: 14px 20px; border-bottom: 1px solid #f0f0f0; font-weight: 600; display: flex; justify-content: space-between; }
.modal-head .x { cursor: pointer; color: #999; font-weight: normal; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-body.chatview { background: #f5f6f8; }
.modal-foot { padding: 12px 20px; border-top: 1px solid #f0f0f0; display: flex; justify-content: flex-end; gap: 10px; }
.modal .field { margin-bottom: 12px; }
.modal .field label { display: block; font-size: 13px; color: #666; margin-bottom: 4px; }
.modal .field input, .modal .field select, .modal .field textarea { width: 100%; }
.agent-opt { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 1px solid #f0f0f0; border-radius: 6px; margin-bottom: 8px; cursor: pointer; }
.agent-opt:hover { border-color: #91caff; }

.toast { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); background: #fff; padding: 10px 20px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.15); z-index: 200; font-size: 14px; }
.toast.err { color: #cf1322; }
.toast.ok { color: #389e0d; }
.preview { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 300; cursor: zoom-out; }
.preview img { max-width: 92%; max-height: 92%; }

@media (max-width: 1100px) { .info-side { display: none; } }
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .conv-side { width: 100%; }
  .work.chatting .conv-side { display: none; }
  .work:not(.chatting) .chat-main { display: none; }
  .me #myName { display: none; }
}
