/* 浩学自托管客服系统 - 共享样式 */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root{
  --blue:#1a73e8; --blue-d:#1557b0; --green:#0f9d6e; --red:#e5484d;
  --ink:#1f2937; --muted:#6b7280; --line:#e5e7eb; --bg:#f5f6f8; --card:#fff;
}
body{ font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;
  color:var(--ink); background:var(--bg); font-size:14px; line-height:1.6; }
a{ color:var(--blue); text-decoration:none; }
button{ font-family:inherit; cursor:pointer; border:none; background:none; }
input,textarea,select{ font-family:inherit; font-size:14px; }

/* ===== 访客聊天窗 ===== */
.chat-wrap{ position:fixed; inset:0; display:flex; flex-direction:column; background:#fff; }
.chat-head{ height:60px; flex-shrink:0; background:linear-gradient(135deg,#1a73e8,#1557b0);
  color:#fff; display:flex; align-items:center; gap:12px; padding:0 16px; box-shadow:0 2px 8px rgba(26,115,232,.25); }
.chat-avatar{ width:40px; height:40px; border-radius:50%; background:#fff; color:var(--blue);
  display:flex; align-items:center; justify-content:center; font-weight:700; font-size:16px; flex-shrink:0; overflow:hidden; }
.chat-avatar img{ width:100%; height:100%; object-fit:cover; }
.chat-head-txt{ flex:1; min-width:0; }
.chat-head-name{ font-size:15px; font-weight:600; }
.chat-head-sub{ font-size:11px; opacity:.85; display:flex; align-items:center; gap:5px; }
.dot-online{ width:7px; height:7px; border-radius:50%; background:#5ce1a0; display:inline-block; }

.chat-body{ flex:1; overflow-y:auto; padding:16px; background:var(--bg); }
.msg{ display:flex; gap:8px; margin-bottom:14px; align-items:flex-start; }
/* 消息体：给气泡一层受控宽度，避免 flex 收缩导致中文逐字断行 */
.msg .msg-body{ min-width:0; flex:0 1 auto; max-width:78%; display:flex; flex-direction:column; align-items:flex-start; }
.msg.visitor .msg-body{ align-items:flex-end; }
.msg .bubble{ width:fit-content; max-width:100%; padding:10px 13px; border-radius:12px; font-size:14px;
  background:#fff; border:1px solid var(--line); word-break:normal; overflow-wrap:anywhere; white-space:pre-wrap; }
.msg.ai .bubble,.msg.agent .bubble,.msg.system .bubble{ background:#fff; border-top-left-radius:2px; }
.msg.visitor{ flex-direction:row-reverse; }
.msg.visitor .bubble{ background:#dbeafe; border-color:#dbeafe; border-top-right-radius:2px; }
.msg.system{ justify-content:center; }
.msg.system .bubble{ background:transparent; border:none; color:var(--muted); font-size:12px;
  max-width:90%; text-align:center; padding:4px; }
.msg .mini-av{ width:30px; height:30px; border-radius:50%; flex-shrink:0; display:flex;
  align-items:center; justify-content:center; font-size:11px; font-weight:600; background:var(--blue); color:#fff; overflow:hidden; }
.msg.visitor .mini-av{ background:#94a3b8; }
.msg .mini-av img{ width:100%; height:100%; object-fit:cover; }
.msg-time{ font-size:10px; color:#9ca3af; margin-top:3px; }
.msg img.chat-img{ max-width:200px; max-height:200px; border-radius:8px; display:block; }

.typing{ display:inline-flex; gap:4px; align-items:center; }
.typing i{ width:6px; height:6px; border-radius:50%; background:#9ca3af; animation:blink 1.2s infinite; }
.typing i:nth-child(2){ animation-delay:.2s; } .typing i:nth-child(3){ animation-delay:.4s; }
@keyframes blink{ 0%,60%,100%{opacity:.3} 30%{opacity:1} }

/* 留资卡片 */
.lead-card{ margin:10px 0; padding:14px; background:#fff; border:1px solid var(--line);
  border-radius:12px; box-shadow:0 2px 10px rgba(0,0,0,.04); }
.lead-card h4{ font-size:14px; margin-bottom:10px; }
.lead-card input{ width:100%; padding:9px 11px; border:1px solid var(--line); border-radius:8px; margin-bottom:8px; }
.lead-card button{ width:100%; padding:10px; background:var(--blue); color:#fff; border-radius:8px; font-weight:600; }

/* 评价卡片 */
.rate-card{ margin:10px 0; padding:14px; background:#fff; border:1px solid var(--line); border-radius:12px; text-align:center; }
.rate-card h4{ font-size:14px; margin-bottom:8px; }
.stars{ font-size:28px; color:#d1d5db; letter-spacing:4px; cursor:pointer; }
.stars .on{ color:#fbbf24; }

.chat-foot{ flex-shrink:0; border-top:1px solid var(--line); background:#fff; padding:10px 12px; }
.quick-tags{ display:flex; gap:6px; overflow-x:auto; padding-bottom:8px; }
.quick-tags button{ flex-shrink:0; padding:6px 11px; border:1px solid #c7dbfb; color:var(--blue);
  border-radius:16px; font-size:12px; background:#f0f6ff; white-space:nowrap; }
.quick-tags .human-tag{ border-color:#c9a063; color:#fff; background:linear-gradient(135deg,#c9a063,#b8914f); font-weight:600; }
.quick-tags .human-tag:disabled{ opacity:.6; }
.chat-input-row{ display:flex; gap:8px; align-items:flex-end; }
.chat-input-row textarea{ flex:1; resize:none; height:42px; max-height:110px; padding:11px 12px;
  border:1px solid var(--line); border-radius:10px; outline:none; line-height:1.4; }
.chat-input-row textarea:focus{ border-color:var(--blue); }
.icon-btn{ width:42px; height:42px; flex-shrink:0; border-radius:10px; background:var(--bg);
  color:var(--muted); display:flex; align-items:center; justify-content:center; font-size:18px; }
.send-btn{ background:var(--blue); color:#fff; }
.send-btn:disabled{ background:#b6cff5; cursor:default; }

/* ===== 管理/工作台布局 ===== */
.app-shell{ min-height:100vh; }
.topbar{ height:56px; background:#fff; border-bottom:1px solid var(--line); display:flex;
  align-items:center; padding:0 22px; gap:16px; position:sticky; top:0; z-index:10; }
.topbar .logo{ font-size:17px; font-weight:700; color:var(--blue); }
.topbar .spacer{ flex:1; }
.topbar .user{ font-size:13px; color:var(--muted); }
.topbar button{ padding:7px 14px; border:1px solid var(--line); border-radius:8px; color:var(--ink); background:#fff; font-size:13px; }

.layout{ display:flex; min-height:calc(100vh - 56px); }
.sidebar{ width:200px; flex-shrink:0; background:#fff; border-right:1px solid var(--line); padding:14px 10px; }
.sidebar a{ display:block; padding:10px 14px; border-radius:8px; color:#374151; font-size:14px; margin-bottom:4px; }
.sidebar a:hover{ background:var(--bg); }
.sidebar a.active{ background:#e8f0fe; color:var(--blue); font-weight:600; }
.main{ flex:1; padding:24px 28px; min-width:0; overflow-x:auto; }

.page-head{ display:flex; align-items:center; justify-content:space-between; margin-bottom:20px; }
.page-head h2{ font-size:20px; font-weight:700; }
.page-head .sub{ color:var(--muted); font-size:13px; margin-top:3px; }
.btn{ padding:9px 16px; border-radius:8px; font-size:14px; font-weight:500; }
.btn-primary{ background:var(--blue); color:#fff; }
.btn-primary:hover{ background:var(--blue-d); }
.btn-ghost{ border:1px solid var(--line); background:#fff; color:var(--ink); }
.btn-danger{ background:#fee; color:var(--red); border:1px solid #fcc; }
.btn-sm{ padding:5px 11px; font-size:12px; }

.card{ background:#fff; border:1px solid var(--line); border-radius:12px; padding:20px; margin-bottom:18px; }
.card h3{ font-size:15px; font-weight:600; margin-bottom:14px; }

.grid{ display:grid; gap:16px; }
.grid.cols-4{ grid-template-columns:repeat(4,minmax(0,1fr)); }
.grid.cols-3{ grid-template-columns:repeat(3,minmax(0,1fr)); }
.grid.cols-2{ grid-template-columns:repeat(2,minmax(0,1fr)); }
@media(max-width:900px){ .grid.cols-4{grid-template-columns:repeat(2,1fr)} .grid.cols-3,.grid.cols-2{grid-template-columns:1fr} }

.metric{ background:#fff; border:1px solid var(--line); border-radius:12px; padding:16px 18px; }
.metric .lbl{ font-size:12px; color:var(--muted); }
.metric .val{ font-size:28px; font-weight:700; margin-top:6px; color:var(--ink); }
.metric .val.blue{ color:var(--blue); } .metric .val.green{ color:var(--green); } .metric .val.red{ color:var(--red); }

table.data{ width:100%; border-collapse:collapse; font-size:13px; }
table.data th,table.data td{ text-align:left; padding:10px 12px; border-bottom:1px solid var(--line); vertical-align:top; }
table.data th{ color:var(--muted); font-weight:500; background:#fafbfc; }
table.data tr:hover td{ background:#fafbfc; }
.badge{ display:inline-block; padding:2px 9px; border-radius:12px; font-size:11px; font-weight:500; }
.badge.blue{ background:#e8f0fe; color:var(--blue); }
.badge.green{ background:#e6f7f0; color:var(--green); }
.badge.gray{ background:#f1f2f4; color:var(--muted); }
.badge.red{ background:#fee; color:var(--red); }
.badge.amber{ background:#fff4e0; color:#b45309; }

.field{ margin-bottom:14px; }
.field label{ display:block; font-size:13px; color:#374151; margin-bottom:6px; font-weight:500; }
.field input,.field textarea,.field select{ width:100%; padding:9px 11px; border:1px solid var(--line);
  border-radius:8px; outline:none; background:#fff; }
.field input:focus,.field textarea:focus,.field select:focus{ border-color:var(--blue); }
.field textarea{ min-height:80px; resize:vertical; }
.field .hint{ font-size:11px; color:var(--muted); margin-top:4px; }
.row-between{ display:flex; align-items:center; justify-content:space-between; gap:12px; }
.switch{ position:relative; width:42px; height:24px; }
.switch input{ opacity:0; width:0; height:0; }
.switch .slider{ position:absolute; inset:0; background:#cbd5e1; border-radius:24px; transition:.2s; }
.switch .slider:before{ content:""; position:absolute; width:18px; height:18px; left:3px; top:3px;
  background:#fff; border-radius:50%; transition:.2s; }
.switch input:checked + .slider{ background:var(--blue); }
.switch input:checked + .slider:before{ transform:translateX(18px); }

/* 工作台双栏 */
.workbench{ display:flex; gap:16px; height:calc(100vh - 56px - 48px); }
.wb-list{ width:320px; flex-shrink:0; background:#fff; border:1px solid var(--line); border-radius:12px;
  overflow-y:auto; }
.wb-item{ padding:13px 15px; border-bottom:1px solid var(--line); cursor:pointer; }
.wb-item:hover{ background:#fafbfc; } .wb-item.active{ background:#e8f0fe; border-left:3px solid var(--blue); }
.wb-item .t{ display:flex; justify-content:space-between; font-size:13px; font-weight:600; }
.wb-item .t .time{ font-size:11px; color:var(--muted); font-weight:400; }
.wb-item .p{ font-size:12px; color:var(--muted); margin-top:4px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.wb-chat{ flex:1; display:flex; flex-direction:column; background:#fff; border:1px solid var(--line); border-radius:12px; min-width:0; }
.wb-chat-head{ padding:12px 16px; border-bottom:1px solid var(--line); display:flex; align-items:center; gap:10px; }
.wb-chat-head .spacer{ flex:1; }
.wb-msgs{ flex:1; overflow-y:auto; padding:16px; background:var(--bg); }
.wb-input{ padding:12px; border-top:1px solid var(--line); display:flex; gap:8px; }
.wb-input textarea{ flex:1; resize:none; height:46px; padding:10px; border:1px solid var(--line); border-radius:8px; outline:none; }
.wb-quick{ display:flex; gap:6px; padding:0 12px 8px; overflow-x:auto; }
.wb-quick button{ flex-shrink:0; font-size:11px; padding:5px 10px; border:1px solid var(--line);
  border-radius:14px; background:#fff; color:var(--muted); }

/* 登录页 */
.login-page{ min-height:100vh; display:flex; align-items:center; justify-content:center;
  background:linear-gradient(135deg,#e8f0fe,#f5f6f8); }
.login-box{ width:380px; max-width:92vw; background:#fff; border-radius:16px; padding:32px;
  box-shadow:0 10px 40px rgba(0,0,0,.08); }
.login-box .brand{ text-align:center; margin-bottom:24px; }
.login-box .brand .ic{ width:52px; height:52px; border-radius:14px; background:var(--blue); color:#fff;
  display:flex; align-items:center; justify-content:center; font-size:22px; font-weight:700; margin:0 auto 12px; }
.login-box .brand h1{ font-size:19px; } .login-box .brand p{ color:var(--muted); font-size:13px; }
.login-box .btn{ width:100%; padding:11px; margin-top:6px; }

.toast{ position:fixed; top:20px; left:50%; transform:translateX(-50%); background:#1f2937; color:#fff;
  padding:10px 18px; border-radius:8px; font-size:13px; z-index:999; box-shadow:0 4px 16px rgba(0,0,0,.2); }
.empty{ text-align:center; color:var(--muted); padding:40px 20px; font-size:13px; }
.spinner{ text-align:center; color:var(--muted); padding:20px; font-size:13px; }

/* ===== 移动端工作台：单栏切换，保证手机上也能接待对话 ===== */
.wb-back{ display:none; }
@media(max-width:760px){
  .topbar{ height:auto; min-height:54px; flex-wrap:wrap; padding:8px 12px; gap:8px; position:relative; }
  .topbar .logo{ font-size:15px; }
  .topbar .user{ font-size:12px; }
  .topbar button{ padding:6px 10px; font-size:12px; }
  .main{ padding:12px !important; }
  .page-head{ margin-bottom:12px; }
  .page-head h2{ font-size:17px; }
  .workbench{ display:block; height:calc(100vh - 120px); }
  .wb-list{ width:100%; height:100%; border:1px solid var(--line); }
  .wb-chat{ display:none; height:100%; }
  .workbench.mobile-chat-open .wb-list{ display:none; }
  .workbench.mobile-chat-open .wb-chat{ display:flex; }
  .wb-back{ display:inline-flex; align-items:center; padding:4px 9px; margin-right:6px;
    border:1px solid var(--line); border-radius:8px; background:#fff; color:var(--blue); font-size:13px; }
  .wb-chat-head{ padding:10px 12px; }
  .wb-input{ padding:8px; }
  .wb-input textarea{ height:42px; font-size:16px; }
  .msg .bubble{ font-size:15px; }
  .msg .msg-body{ max-width:82%; }
}
