:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --primary: #4f6ef7;
  --primary-dark: #3d5af1;
  --text: #1f2937;
  --text-soft: #6b7280;
  --border: #e5e7eb;
  --bubble-visitor: #4f6ef7;
  --bubble-admin: #ffffff;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 16px;
  --green: #22c55e;
  --red: #ef4444;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button { font: inherit; cursor: pointer; border: none; }
input, textarea { font: inherit; outline: none; }

/* ===== 通用布局 ===== */
.app { height: 100vh; display: flex; overflow: hidden; }

.sidebar {
  width: 320px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-title { font-size: 16px; font-weight: 600; }
.sidebar-sub { font-size: 12px; color: var(--text-soft); margin-top: 2px; }

.toolbar {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.toolbar input[type="text"] {
  flex: 1;
  min-width: 130px;
  padding: 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 13px;
}
.toolbar input[type="text"]:focus { border-color: var(--primary); }

.tool-btn {
  padding: 8px 11px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-soft);
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.tool-btn:hover { background: #e5e9f5; color: var(--primary); }

.conv-list { flex: 1; overflow-y: auto; padding: 8px; }

.conv-item {
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  gap: 12px;
  align-items: center;
  transition: background 0.15s;
  position: relative;
}
.conv-item:hover { background: #f3f4f6; }
.conv-item.active { background: #eef2ff; }
.conv-item .meta { flex: 1; min-width: 0; }
.conv-item .name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}
.conv-item .note-tag {
  font-size: 11px;
  color: #b45309;
  background: #fef3c7;
  padding: 1px 6px;
  border-radius: 6px;
  font-weight: 500;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-item .preview {
  font-size: 12px;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}
.conv-item .right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; }
.conv-item .time { font-size: 11px; color: var(--text-soft); }
.conv-item .badge {
  background: var(--red);
  color: #fff;
  font-size: 11px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #cbd5e1;
  flex-shrink: 0;
}
.status-dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,0.15); }

.empty-tip { padding: 40px 20px; text-align: center; color: var(--text-soft); font-size: 13px; }

/* ===== 聊天主区 ===== */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-header {
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header .name { font-size: 16px; font-weight: 600; }
.chat-header .status { font-size: 12px; color: var(--text-soft); display: flex; align-items: center; gap: 6px; }
.chat-header .spacer { flex: 1; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #f3f4f6;
  color: var(--text-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: #e5e7eb; color: var(--text); }
.icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.messages { flex: 1; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 14px; }

.load-more { align-self: center; font-size: 12px; color: var(--text-soft); padding: 6px 14px; border-radius: 20px; background: #eef0f5; }
.load-more.disabled { opacity: 0.45; }

.msg-row { display: flex; gap: 10px; max-width: 72%; align-self: flex-start; }
.msg-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-row .avatar { width: 34px; height: 34px; font-size: 13px; }

.bubble {
  padding: 11px 15px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: var(--shadow);
}
.msg-row.mine .bubble { background: var(--bubble-visitor); color: #fff; border-bottom-right-radius: 4px; }
.msg-row.other .bubble { background: var(--bubble-admin); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble .text:empty { display: none; }

.msg-time { font-size: 11px; color: var(--text-soft); margin-top: 5px; }
.msg-row.mine .msg-time { text-align: right; }
.msg-sender { font-size: 11px; color: var(--text-soft); margin-bottom: 4px; }

.attachment-img {
  display: block;
  max-width: 260px;
  max-height: 220px;
  border-radius: 10px;
  margin-top: 6px;
  cursor: pointer;
}
.attachment-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.16);
  border: 1px solid rgba(255,255,255,0.25);
  text-decoration: none;
  color: inherit;
  max-width: 280px;
}
.msg-row.other .attachment-card { background: var(--bg); border-color: var(--border); }
.attachment-card .file-icon { font-size: 20px; }
.attachment-card .file-meta { flex: 1; min-width: 0; }
.attachment-card .file-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attachment-card .file-size { font-size: 11px; opacity: 0.7; }

.day-divider { align-self: center; font-size: 12px; color: var(--text-soft); background: #eef0f5; padding: 4px 12px; border-radius: 20px; }

.typing-indicator {
  align-self: flex-start;
  font-size: 12px;
  color: var(--text-soft);
  padding: 4px 12px;
  display: none;
}
.typing-indicator.show { display: block; }

/* ===== 输入区 ===== */
.composer { padding: 14px 22px 18px; background: var(--panel); border-top: 1px solid var(--border); }
.composer-box { display: flex; align-items: flex-end; gap: 10px; background: var(--bg); border-radius: 18px; padding: 9px 11px; border: 1px solid var(--border); }
.composer textarea { flex: 1; border: none; background: transparent; resize: none; font-size: 14px; line-height: 1.5; max-height: 120px; min-height: 24px; color: var(--text); }
.attach-btn { width: 38px; height: 38px; border-radius: 10px; background: transparent; color: var(--text-soft); font-size: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.attach-btn:hover { background: #e5e7eb; }
.send-btn { width: 42px; height: 42px; border-radius: 12px; background: var(--primary); color: #fff; font-size: 16px; display: flex; align-items: center; justify-content: center; transition: background 0.15s, transform 0.1s; flex-shrink: 0; }
.send-btn:hover { background: var(--primary-dark); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { background: #c7cddb; cursor: not-allowed; }
.upload-hint { font-size: 12px; color: var(--primary); padding: 4px 0 0 4px; min-height: 18px; }

/* ===== 遮罩 / 弹窗 ===== */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.45); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; z-index: 50; }
.login-card, .modal-card { background: var(--panel); border-radius: 20px; padding: 32px 30px; width: min(420px, calc(100vw - 40px)); box-shadow: var(--shadow); text-align: center; max-height: 84vh; overflow-y: auto; }
.login-card h1, .modal-card h1 { font-size: 21px; margin-bottom: 8px; }
.login-card p, .modal-card p { color: var(--text-soft); font-size: 13px; margin-bottom: 20px; }
.login-card input, .modal-card input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); font-size: 14px; margin-bottom: 12px; }
.login-card input:focus, .modal-card input:focus { border-color: var(--primary); }
.primary-btn { width: 100%; padding: 12px; border-radius: 12px; background: var(--primary); color: #fff; font-size: 15px; font-weight: 600; transition: background 0.15s; }
.primary-btn:hover { background: var(--primary-dark); }
.primary-btn:disabled { background: #c7cddb; cursor: not-allowed; }
.link-btn { background: none; color: var(--primary); font-size: 13px; margin-top: 12px; }
.link-btn:hover { text-decoration: underline; }

/* 蜜罐字段：移出视口 + 零尺寸，真人不可见不可聚焦；不用 display:none（部分机器人会跳过） */
.hp-field {
  position: absolute;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.error-text { color: var(--red); font-size: 13px; margin-bottom: 12px; min-height: 18px; }
.captcha-row { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.captcha-row input { flex: 1; min-width: 0; margin-bottom: 0 !important; text-transform: uppercase; letter-spacing: 2px; }
.captcha-row img { width: 148px; height: 48px; flex-shrink: 0; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; background: var(--bg); }
.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab { flex: 1; padding: 9px; border-radius: 10px; background: var(--bg); color: var(--text-soft); font-size: 13px; }
.tab.active { background: var(--primary); color: #fff; }
.modal-close { float: right; font-size: 18px; color: var(--text-soft); background: none; line-height: 1; }
.admin-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--bg); margin-bottom: 8px; text-align: left; }
.admin-row .meta { flex: 1; min-width: 0; }
.admin-row .n { font-size: 14px; font-weight: 600; }
.admin-row .t { font-size: 11px; color: var(--text-soft); }
.danger-btn { padding: 6px 10px; border-radius: 8px; background: #fee2e2; color: #dc2626; font-size: 12px; }
.danger-btn:hover { background: #fecaca; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }

/* ===== 搜索结果 ===== */
.search-panel { position: absolute; top: 58px; left: 12px; right: 12px; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--border); z-index: 20; max-height: 320px; overflow-y: auto; display: none; }
.search-panel.show { display: block; }
.search-item { padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: #f3f4f6; }
.search-item .who { font-size: 12px; color: var(--primary); font-weight: 600; }
.search-item .txt { font-size: 13px; margin-top: 3px; word-break: break-word; }
.search-item .when { font-size: 11px; color: var(--text-soft); margin-top: 3px; }

/* ===== 欢迎语 / 提示 ===== */
.welcome { align-self: center; text-align: center; color: var(--text-soft); margin-top: 8vh; }
.welcome h2 { color: var(--text); font-size: 18px; margin-bottom: 8px; }
.welcome p { font-size: 13px; line-height: 1.8; }
.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: rgba(31,41,55,0.92); color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 13px; z-index: 80; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.toast.show { opacity: 1; }

/* ===== 表情 / 话术面板 ===== */
.composer { position: relative; }
.emoji-btn, .canned-btn, .ai-btn { width: 38px; height: 38px; border-radius: 10px; background: transparent; color: var(--text-soft); font-size: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.emoji-btn:hover, .canned-btn:hover, .ai-btn:hover { background: #e5e7eb; }
.ai-btn { color: #7c3aed; }
.ai-btn:disabled { opacity: .55; cursor: wait; }
.canned-section { font-size: 11px; color: #7c3aed; font-weight: 600; padding: 10px 12px 4px; }
.cloud-tag { color: #7c3aed; margin-right: 2px; }
.emoji-panel { display: none; position: absolute; bottom: 64px; left: 14px; width: 288px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 8px; grid-template-columns: repeat(6, 1fr); gap: 2px; max-height: 184px; overflow-y: auto; z-index: 40; }
.emoji-panel.show { display: grid; }
.emoji-item { font-size: 20px; padding: 6px; border-radius: 8px; background: none; text-align: center; }
.emoji-item:hover { background: var(--bg); }
.canned-panel { display: none; position: absolute; bottom: 64px; left: 14px; right: 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 8px; max-height: 260px; overflow-y: auto; z-index: 40; }
.canned-panel.show { display: block; }
.canned-item { padding: 10px 12px; border-radius: 10px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.canned-item:hover { background: var(--bg); }
.canned-item:last-child { border-bottom: none; }
.canned-add { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border); margin-top: 6px; }
.canned-add input { flex: 1; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); font-size: 13px; }
.canned-add button { padding: 8px 12px; border-radius: 8px; background: var(--primary); color: #fff; font-size: 13px; }

/* ===== 撤回 ===== */
.msg-recall { align-self: center; font-size: 12px; color: var(--text-soft); background: #eef0f5; padding: 4px 12px; border-radius: 12px; margin: 4px 0; }
.recall-btn { align-self: center; font-size: 11px; color: var(--red); background: #fee2e2; border-radius: 6px; padding: 2px 8px; margin-left: 6px; opacity: 0; transition: opacity 0.15s; }
.msg-row:hover .recall-btn { opacity: 1; }

/* ===== 会话分配 / 联系方式 ===== */
.assign-tag { font-size: 11px; color: #1d4ed8; background: #dbeafe; padding: 1px 6px; border-radius: 6px; font-weight: 500; margin-left: 6px; }
.assign-btn { font-size: 11px; color: var(--primary); background: #eef2ff; border-radius: 6px; padding: 2px 8px; margin-top: 3px; }
.contact-line { font-size: 12px; color: var(--text-soft); margin-top: 3px; }
.contact-line span { margin-right: 10px; }
.device-line { font-size: 11px; color: var(--text-soft); margin-top: 2px; opacity: 0.85; word-break: break-all; }

@media (max-width: 720px) {
  .sidebar { display: none; }
  .sidebar.show { display: flex; position: fixed; inset: 0; width: 100%; z-index: 30; }
  .msg-row { max-width: 88%; }
  .search-panel { position: fixed; }
}
