:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff6ff;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: white;
}
.brand-text { font-weight: 700; font-size: 15px; letter-spacing: .2px; }
.brand-sub { color: var(--muted); font-size: 12px; padding-left: 10px; border-left: 1px solid var(--border); }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.agent-badge { display: inline-flex; align-items: center; gap: 7px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 11px 4px 5px; font-size: 12px; }
.agent-badge .mini-avatar { width: 23px; height: 23px; border-radius: 50%; background: var(--primary); color: white; display: grid; place-items: center; font-size: 10px; font-weight: 700; }
.agent-badge .role { color: var(--muted); font-size: 10px; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.conn i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.conn.status-online { color: var(--green); }
.conn.status-online i { background: var(--green); box-shadow: 0 0 0 3px rgba(22,163,74,.14); }
.conn.status-offline { color: var(--red); }
.conn.status-offline i { background: var(--red); }

.btn {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 7px 13px; font-size: 13px; font-weight: 600;
  transition: .16s ease; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--surface-2); border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--red); border-color: #fecaca; background: #fef2f2; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 16px; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); }

/* ---------- 布局 ---------- */
.layout {
  height: calc(100vh - 60px);
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 270px;
}

/* ---------- 左侧 ---------- */
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head { padding: 18px 16px 12px; display: flex; justify-content: space-between; align-items: flex-start; }
.sidebar-head h2 { margin: 0 0 4px; font-size: 14px; }
.sidebar-head p { margin: 0; font-size: 11px; color: var(--muted); }
.pill { background: var(--primary-soft); color: var(--primary); border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 700; }
.site-tabs { display: flex; gap: 6px; padding: 0 12px 12px; overflow-x: auto; flex-shrink: 0; }
.site-tab {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px;
  padding: 5px 11px; font-size: 12px; color: var(--muted); white-space: nowrap; transition: .15s;
}
.site-tab:hover { border-color: var(--primary); color: var(--primary); }
.site-tab.active { background: var(--primary); border-color: var(--primary); color: white; font-weight: 600; }
.visitor-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.visitor-item {
  display: flex; gap: 10px; padding: 11px 10px; border-radius: 10px;
  cursor: pointer; transition: .14s; border: 1px solid transparent; margin-bottom: 2px;
}
.visitor-item:hover { background: var(--surface-2); }
.visitor-item.active { background: var(--primary-soft); border-color: #bfdbfe; }
.avatar {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; color: white; font-weight: 700; font-size: 13px;
}
.visitor-main { flex: 1; min-width: 0; }
.visitor-row { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.visitor-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.visitor-time { font-size: 10px; color: var(--muted); flex-shrink: 0; }
.visitor-preview { font-size: 11px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.visitor-tags { display: flex; gap: 5px; align-items: center; margin-top: 5px; }
.tag { font-size: 10px; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.tag.online { color: var(--green); border-color: #bbf7d0; background: #f0fdf4; }
.tag.offline { color: var(--muted); }
.unread { background: var(--red); color: white; border-radius: 999px; font-size: 10px; min-width: 17px; height: 17px; display: grid; place-items: center; padding: 0 5px; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 10px 16px; font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.dot-live { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }

/* ---------- 中间对话区 ---------- */
.chat-panel { display: flex; flex-direction: column; min-width: 0; background: var(--surface-2); }
.chat-header {
  height: 64px; flex-shrink: 0; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; justify-content: space-between;
}
.empty-header { color: var(--muted); font-size: 13px; }
.chat-title { display: flex; align-items: center; gap: 10px; }
.chat-title h2 { margin: 0; font-size: 15px; }
.chat-title .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.chat-actions { display: flex; gap: 8px; }

.messages { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.chat-empty { margin: auto; text-align: center; color: var(--muted); }
.chat-empty-icon {
  width: 70px; height: 70px; border-radius: 20px; background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; margin: 0 auto 16px;
}
.chat-empty h3 { color: var(--text); margin: 0 0 8px; font-size: 16px; }
.chat-empty p { margin: 0; line-height: 1.8; font-size: 13px; }

.msg { display: flex; gap: 10px; max-width: 76%; }
.msg.visitor { align-self: flex-start; }
.msg.agent { align-self: flex-end; flex-direction: row-reverse; }
.msg .avatar { width: 30px; height: 30px; border-radius: 9px; font-size: 11px; }
.bubble {
  background: var(--surface); border: 1px solid var(--border); border-radius: 4px 14px 14px 14px;
  padding: 10px 13px; box-shadow: var(--shadow); min-width: 100px;
}
.msg.agent .bubble { background: var(--primary); color: white; border-color: var(--primary); border-radius: 14px 4px 14px 14px; }
.msg-text { white-space: pre-wrap; word-break: break-word; line-height: 1.55; font-size: 13px; }
.msg-translation {
  margin-top: 8px; padding-top: 7px; border-top: 1px dashed rgba(100,116,139,.35);
  font-size: 11.5px; line-height: 1.5; color: var(--muted);
}
.msg.agent .msg-translation { border-top-color: rgba(255,255,255,.3); color: rgba(255,255,255,.85); }
.msg-translation .tr-label { font-weight: 700; margin-right: 4px; opacity: .9; }
.msg-meta { margin-top: 6px; font-size: 10px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.msg.agent .msg-meta { color: rgba(255,255,255,.72); }
.tr-fail { color: var(--amber); font-weight: 600; }
.msg.agent .tr-fail { color: #fde68a; }

.typing-line { height: 22px; padding: 0 24px; font-size: 11px; color: var(--muted); flex-shrink: 0; }
.typing-line span { display: inline-flex; gap: 4px; align-items: center; }
.typing-dots i { width: 4px; height: 4px; background: var(--muted); border-radius: 50%; animation: blink 1.2s infinite; }
.typing-dots i:nth-child(2) { animation-delay: .2s; }
.typing-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100% { opacity: .25; } 30% { opacity: 1; } }

.composer { flex-shrink: 0; background: var(--surface); border-top: 1px solid var(--border); padding: 10px 16px 14px; position: relative; }
.composer-tools { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.chip-btn { border: 1px solid var(--border); background: var(--surface-2); border-radius: 7px; padding: 4px 10px; font-size: 11px; color: var(--muted); }
.chip-btn:hover, .chip-btn.active { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.lang-hint { font-size: 11px; color: var(--muted); }
.composer-box { display: flex; gap: 10px; align-items: flex-end; }
.composer-box textarea {
  flex: 1; resize: none; border: 1px solid var(--border-strong); border-radius: 9px;
  padding: 10px 12px; font-size: 13px; outline: none; background: var(--surface); color: var(--text); line-height: 1.5;
}
.composer-box textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.composer-box .btn { height: 38px; padding: 0 20px; }
.quick-panel {
  position: absolute; bottom: 100%; left: 16px; right: 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(15,23,42,.12);
  padding: 8px; max-height: 220px; overflow-y: auto; margin-bottom: 6px;
}
.quick-item { padding: 9px 11px; border-radius: 7px; cursor: pointer; font-size: 12px; }
.quick-item:hover { background: var(--primary-soft); }
.quick-item strong { display: block; margin-bottom: 3px; }
.quick-item span { color: var(--muted); }

/* ---------- 右侧 ---------- */
.info-panel { background: var(--surface); border-left: 1px solid var(--border); overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.info-card { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.info-card h3 { margin: 0; padding: 11px 13px; font-size: 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.info-body { padding: 13px; font-size: 12px; }
.info-body .muted { color: var(--muted); margin: 0; }
.info-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.info-row:last-child { border-bottom: 0; }
.info-row .k { color: var(--muted); flex-shrink: 0; }
.info-row .v { font-weight: 600; text-align: right; word-break: break-all; }
.embed-code {
  background: #0f172a; color: #93c5fd; border-radius: 8px; padding: 10px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 10px; line-height: 1.6; word-break: break-all; margin: 8px 0;
}
.translate-status { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--green); }
.ts-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.hint { color: var(--muted); line-height: 1.7; font-size: 11px; margin: 8px 0 0; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.4); backdrop-filter: blur(2px); }
.modal-card { position: relative; background: var(--surface); border-radius: 16px; width: min(620px, 92vw); max-height: 84vh; overflow: auto; box-shadow: 0 24px 60px rgba(15,23,42,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px 22px 24px; }
.modal-body section { margin-bottom: 26px; }
.modal-body h3 { margin: 0 0 10px; font-size: 13px; }
.settings-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.settings-item { display: flex; justify-content: space-between; align-items: center; padding: 9px 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; font-size: 12px; }
.settings-item .meta { color: var(--muted); font-size: 11px; margin-left: 8px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; outline: none; font-size: 12px; }
.inline-form input:focus { border-color: var(--primary); }
.agent-site-hint { font-size: 11px; color: var(--muted); margin-top: 8px; }
.agent-item { align-items: flex-start; gap: 10px; }
.agent-controls { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; align-items: center; }
.agent-controls .site-mini { border: 1px solid var(--border); background: white; color: var(--muted); border-radius: 6px; padding: 3px 7px; font-size: 10px; cursor: pointer; }
.agent-controls .site-mini.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.agent-controls .btn { padding: 3px 8px; font-size: 10px; }
.btn-tiny { border: 1px solid var(--border); background: white; border-radius: 6px; padding: 3px 8px; font-size: 10px; color: var(--muted); }
.btn-tiny:hover { border-color: var(--primary); color: var(--primary); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: #0f172a; color: white; padding: 10px 18px; border-radius: 9px; font-size: 12px; opacity: 0; pointer-events: none; transition: .25s; z-index: 100; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); }
  .info-panel { display: none; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .brand-sub { display: none; }
}
