/* ============================================================
   微信客服管理后台 - 全局样式（基于 DESIGN.md）
   主色：深靛蓝  |  背景：冷灰白  |  在线：翠绿  |  未读：珊瑚红
   ============================================================ */
:root {
  --primary: #3d41a3;
  --primary-2: oklch(0.45 0.15 260);
  --primary-weak: #eef0fb;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e5e7eb;
  --online: #22c55e;
  --danger: #ef4444;
  --text: #0f172a;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --radius-card: 8px;
  --radius-btn: 6px;
  --radius-bubble: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  --transition: 0.15s ease;
}

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

/* ---------- 通用 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border: 1px solid var(--border); border-radius: var(--radius-btn);
  background: var(--card); color: var(--text); font-size: 14px; transition: var(--transition);
  white-space: nowrap;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); color: #fff; }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; border-color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > span { font-size: 13px; color: var(--text-2); }
.field input[type="text"], .field input[type="password"], .field input[type="number"], .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-btn); background: #fff; transition: var(--transition);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(61,65,163,0.12); }

.form-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; border-radius: var(--radius-btn); padding: 8px 12px; margin-bottom: 14px; font-size: 13px; }
.form-hint { font-size: 12px; color: var(--text-3); margin-top: 6px; }

/* ---------- 登录页 ---------- */
.login-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: linear-gradient(135deg, #f8fafc 0%, #eef0fb 100%);
}
.login-card {
  width: 380px; background: var(--card); border-radius: 12px; box-shadow: var(--shadow);
  padding: 36px 32px 28px;
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-logo {
  width: 52px; height: 52px; border-radius: 12px; background: var(--primary);
  color: #fff; font-size: 24px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; margin-bottom: 12px;
}
.login-brand h1 { font-size: 18px; font-weight: 600; }
.login-brand p { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.login-hint { margin-top: 14px; text-align: center; font-size: 12px; color: var(--text-3); }

/* ---------- 三栏工作台布局 ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }

/* 左侧导航 60px */
.sidebar {
  width: 60px; background: var(--text); color: #fff; display: flex; flex-direction: column;
  align-items: center; padding: 14px 0; gap: 6px; flex-shrink: 0;
}
.sidebar .logo {
  width: 36px; height: 36px; border-radius: 10px; background: var(--primary);
  color: #fff; font-size: 16px; font-weight: 600; display: flex; align-items: center; justify-content: center; margin-bottom: 14px;
}
.nav-item {
  width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  color: #cbd5e1; position: relative; transition: var(--transition);
}
.nav-item:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item svg { width: 20px; height: 20px; }
.nav-item .tip {
  position: absolute; left: 52px; top: 50%; transform: translateY(-50%); background: var(--text);
  color: #fff; padding: 4px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: var(--transition); z-index: 50;
}
.nav-item:hover .tip { opacity: 1; }
.sidebar .spacer { flex: 1; }
.sidebar .logout { color: #94a3b8; }
.sidebar .logout:hover { background: rgba(239,68,68,0.15); color: #ef4444; }

/* 对话列表 320px */
.conversation-col { width: 320px; background: #fff; border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.conv-header { padding: 16px 16px 12px; border-bottom: 1px solid var(--border); }
.conv-header h2 { font-size: 16px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; }
.conv-header h2 .count { font-size: 12px; font-weight: 400; color: var(--text-3); }
.conv-search { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-btn); background: var(--bg); font-size: 13px; }
.conv-search:focus { border-color: var(--primary); background: #fff; }
.conv-tabs { display: flex; gap: 4px; margin-top: 10px; border-bottom: 1px solid var(--border); }
.conv-tab {
  padding: 6px 10px; font-size: 13px; color: var(--text-2); background: none; border: none;
  border-bottom: 2px solid transparent; transition: var(--transition);
}
.conv-tab:hover { color: var(--text); }
.conv-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.conv-list { flex: 1; overflow-y: auto; }
.conv-item {
  display: flex; gap: 10px; padding: 12px 16px; cursor: pointer; border-left: 3px solid transparent; transition: var(--transition);
  align-items: flex-start;
}
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--primary-weak); border-left-color: var(--primary); }
.conv-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary-weak); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 600; flex-shrink: 0; }
.conv-main { flex: 1; min-width: 0; }
.conv-row { display: flex; justify-content: space-between; align-items: center; }
.conv-name { font-size: 14px; font-weight: 500; }
.conv-time { font-size: 11px; color: var(--text-3); }
.conv-last { font-size: 12px; color: var(--text-2); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { display: flex; align-items: center; gap: 6px; margin-top: 5px; }
.conv-badge { font-size: 11px; color: var(--text-2); background: var(--bg); border: 1px solid var(--border); padding: 1px 6px; border-radius: 4px; }
.conv-badge.waiting { color: #b45309; background: #fff7ed; border-color: #fed7aa; }
.conv-badge.closed { color: var(--text-3); }
.conv-unread { min-width: 18px; height: 18px; padding: 0 5px; background: var(--danger); color: #fff; font-size: 11px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-weight: 600; }
.conv-empty { padding: 40px 16px; text-align: center; color: var(--text-3); font-size: 13px; }

/* 对话窗口 */
.chat-col { flex: 1; display: flex; flex-direction: column; background: var(--bg); min-width: 0; }
.chat-header {
  height: 62px; background: #fff; border-bottom: 1px solid var(--border); padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.chat-user h3 { font-size: 16px; font-weight: 600; }
.chat-user span { font-size: 12px; color: var(--text-3); }
.chat-actions { display: flex; gap: 8px; }
.messages { flex: 1; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.msg-system { text-align: center; font-size: 12px; color: var(--text-3); }
.msg { display: flex; gap: 8px; max-width: 72%; }
.msg .msg-av { width: 30px; height: 30px; border-radius: 50%; background: #f1f5f9; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; }
.msg.user { align-self: flex-start; }
.msg.agent { align-self: flex-end; flex-direction: row-reverse; }
.msg-body { display: flex; flex-direction: column; gap: 3px; }
.msg-info { font-size: 11px; color: var(--text-3); }
.msg.agent .msg-info { text-align: right; }
.bubble {
  padding: 9px 13px; border-radius: var(--radius-bubble); font-size: 14px; line-height: 1.5; word-break: break-word;
}
.msg.user .bubble { background: #fff; border: 1px solid var(--border); border-top-left-radius: 4px; }
.msg.agent .bubble { background: var(--primary); color: #fff; border-top-right-radius: 4px; }
.msg-empty { margin: auto; text-align: center; color: var(--text-3); font-size: 13px; }

.chat-input-bar { border-top: 1px solid var(--border); background: #fff; padding: 12px 20px; flex-shrink: 0; }
.chat-input-box { display: flex; gap: 10px; align-items: flex-end; }
.chat-input-box textarea {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: var(--radius-bubble);
  padding: 10px 14px; font-size: 14px; line-height: 1.5; max-height: 120px; background: var(--bg);
}
.chat-input-box textarea:focus { border-color: var(--primary); background: #fff; }
.chat-tip { font-size: 11px; color: var(--text-3); margin-top: 6px; }

/* 空状态（无选中对话） */
.chat-empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-3); gap: 8px; }
.chat-empty-state .big { font-size: 44px; }

/* ---------- 通用页面容器（管理员/配置页） ---------- */
.page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.page-side { display: flex; height: 100vh; }
.page-side .sidebar { height: 100vh; }
.page-content { flex: 1; overflow-y: auto; padding: 24px 32px; background: var(--bg); }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-head h2 { font-size: 20px; font-weight: 600; }
.page-head p { font-size: 13px; color: var(--text-2); margin-top: 4px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow); overflow: hidden; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); font-size: 15px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.card-body { padding: 18px; }

/* 表格 */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.table th { color: var(--text-2); font-weight: 500; font-size: 13px; background: #fafbfc; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #fafbfc; }
.avatar-sm { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-weak); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; font-size: 13px; }
.role-badge { padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.role-super { background: #fef3c7; color: #b45309; }
.role-admin { background: #e0e7ff; color: #4338ca; }
.status-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-2); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.status-dot.online { background: var(--online); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* 搜索栏（管理员页） */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type="text"] { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-btn); width: 240px; background: #fff; }

/* Dialog 弹窗 */
.dialog-mask { position: fixed; inset: 0; background: rgba(15,23,42,0.45); display: none; align-items: center; justify-content: center; z-index: 100; }
.dialog-mask.open { display: flex; }
.dialog { width: 440px; max-width: 92vw; background: #fff; border-radius: var(--radius-card); box-shadow: 0 10px 30px rgba(0,0,0,0.2); overflow: hidden; }
.dialog-head { padding: 16px 20px; border-bottom: 1px solid var(--border); font-size: 16px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.dialog-close { background: none; border: none; font-size: 20px; color: var(--text-3); line-height: 1; }
.dialog-body { padding: 20px; }
.dialog-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.role-radio { display: flex; gap: 16px; }
.role-radio label { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }

/* 配置页 */
.sec-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.sec-field-label { font-size: 13px; color: var(--text-2); margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.key-input-wrap { position: relative; }
.key-input-wrap .toggle-key { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: none; color: var(--primary); font-size: 13px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; }
.switch-label { display: flex; flex-direction: column; gap: 3px; }
.switch-label span:first-child { font-size: 15px; font-weight: 500; }
.switch-label span:last-child { font-size: 12px; color: var(--text-3); }
.switch { position: relative; width: 42px; height: 24px; background: var(--border); border-radius: 12px; transition: var(--transition); border: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: var(--transition); box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.switch.on { background: var(--online); }
.switch.on::after { transform: translateX(18px); }
.config-meta { font-size: 12px; color: var(--text-3); margin-top: 6px; }

/* Toast */
.toast-wrap { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--text); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); animation: toastIn 0.25s ease; }
.toast.success { background: #16a34a; }
.toast.error { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 768px) {
  .conversation-col { width: 100%; }
  .chat-col { display: none; }
  .sec-grid { grid-template-columns: 1fr; }
}