/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif; font-size: 14px; line-height: 1.5; color: #333; background: #f0f2f5; }
a { color: #1677ff; text-decoration: none; }
button { font-family: inherit; }

/* ===== Login Page ===== */
.login-page { display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.login-container { width: 100%; max-width: 400px; padding: 20px; }
.login-card { background: #fff; border-radius: 12px; padding: 40px 32px; box-shadow: 0 8px 40px rgba(0, 0, 0, 0.12); }
.login-title { text-align: center; font-size: 28px; font-weight: 700; color: #1677ff; margin-bottom: 4px; }
.login-subtitle { text-align: center; font-size: 14px; color: #999; margin-bottom: 32px; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 14px; font-weight: 500; color: #333; margin-bottom: 6px; }
.form-group input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid #d9d9d9; border-radius: 6px; font-size: 14px; outline: none; transition: border-color 0.2s; }
.form-group input:focus { border-color: #1677ff; box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.1); }
.form-error { color: #ff4d4f; font-size: 13px; margin-bottom: 12px; padding: 8px 12px; background: #fff2f0; border: 1px solid #ffccc7; border-radius: 6px; }

/* ===== Buttons ===== */
.btn-primary { border: none; border-radius: 6px; font-size: 15px; font-weight: 500; cursor: pointer; transition: all 0.2s; background: #1677ff; color: #fff; }
.login-btn { width: 100%; height: 40px; background: #1677ff; color: #fff; }
.login-btn:hover { background: #4096ff; }
.login-btn:disabled { background: #a0c4ff; cursor: not-allowed; }
.send-btn { height: 40px; padding: 0 24px; background: #1677ff; color: #fff; white-space: nowrap; }
.send-btn:hover { background: #4096ff; }
.send-btn:disabled { background: #a0c4ff; cursor: not-allowed; }
.btn-text { background: none; border: none; color: #1677ff; cursor: pointer; padding: 4px 8px; }
.btn-text:hover { color: #4096ff; }
.btn-icon { background: none; border: 1px solid #d9d9d9; border-radius: 4px; cursor: pointer; padding: 4px 8px; font-size: 16px; line-height: 1; }
.btn-icon:hover { background: #f5f5f5; }
.btn-secondary { background: #fff; border: 1px solid #d9d9d9; border-radius: 4px; padding: 6px 16px; cursor: pointer; }
.btn-secondary:hover { border-color: #1677ff; color: #1677ff; }
.btn-outline { background: #fff; border: 1px solid #d9d9d9; border-radius: 4px; padding: 6px 16px; cursor: pointer; }
.btn-outline:hover { border-color: #1677ff; color: #1677ff; }
.btn-sm { font-size: 12px; padding: 4px 12px; margin: 4px 4px 0 0; }

/* ===== App Layout ===== */
.app-layout { display: flex; flex-direction: column; height: 100vh; }

/* Header */
.app-header { display: flex; align-items: center; justify-content: space-between; height: 48px; padding: 0 16px; background: #001529; color: #fff; flex-shrink: 0; }
.header-left { display: flex; align-items: center; gap: 8px; }
.app-brand { font-size: 16px; font-weight: 700; color: #1677ff; }
.header-divider { color: #555; }
.header-title { font-size: 14px; color: #ccc; }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-user { font-size: 13px; color: #ccc; }
.header-right .btn-text { color: #ff7875; }
.header-right .btn-text:hover { color: #ff4d4f; }

/* Body */
.app-body { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ── */
.sidebar { width: 240px; background: #fff; border-right: 1px solid #e8e8e8; display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { padding: 12px 16px; border-bottom: 1px solid #f0f0f0; }
.sidebar-header h3 { font-size: 14px; font-weight: 600; }
.sidebar-search { padding: 8px; }
.sidebar-search input { width: 100%; height: 32px; padding: 0 8px; border: 1px solid #d9d9d9; border-radius: 4px; font-size: 13px; outline: none; }
.sidebar-search input:focus { border-color: #1677ff; }
.sidebar-list { flex: 1; overflow-y: auto; }
.group-item { padding: 10px 16px; cursor: pointer; border-bottom: 1px solid #f5f5f5; transition: background 0.15s; position: relative; display: flex; align-items: center; gap: 10px; }
.group-item-avatar { width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; object-fit: cover; background: #e6f4ff; color: #1677ff; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; }
.group-item-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.group-item-content { flex: 1; min-width: 0; }
.chat-header-avatar { width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; object-fit: cover; background: #e6f4ff; color: #1677ff; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; }
.chat-header-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.group-item:hover { background: #f5f5f5; }
.group-item.active { background: #e6f4ff; border-left: 3px solid #1677ff; }
.group-item-name { font-size: 14px; font-weight: 500; margin-bottom: 2px; }
.group-item-id { font-size: 11px; color: #999; }
.group-item-empty { padding: 24px; text-align: center; color: #999; }
.unread-badge { position: absolute; top: 8px; right: 8px; min-width: 18px; height: 18px; padding: 0 5px; background: #ff4d4f; color: #fff; font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; border-radius: 9px; }

/* ── Chat Main ── */
.chat-main { flex: 1; display: flex; flex-direction: column; background: #f5f5f5; min-width: 0; }

/* Chat Header */
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: #fff; border-bottom: 1px solid #e8e8e8; flex-shrink: 0; }
.chat-header-info { display: flex; align-items: center; gap: 10px; }
.chat-customer-name { font-size: 15px; font-weight: 600; }
.chat-status-badge { font-size: 12px; padding: 2px 8px; border-radius: 10px; }
.chat-status-badge.connected { color: #52c41a; }
.chat-status-badge.disconnected { color: #999; }
.chat-header-actions { display: flex; gap: 4px; }

/* Messages */
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; }
.chat-empty { text-align: center; padding: 60px 20px; color: #999; font-size: 15px; }

/* Message styles */
.msg { margin-bottom: 12px; max-width: 75%; }
.msg-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.msg-sender { font-size: 12px; font-weight: 600; color: #666; }
.msg-time { font-size: 11px; color: #bbb; }
.msg-body { padding: 8px 12px; border-radius: 6px; font-size: 14px; line-height: 1.6; word-break: break-word; white-space: pre-wrap; }

/* Customer messages — left aligned */
.msg-customer { margin-right: auto; }
.msg-customer .msg-body { background: #fff; border: 1px solid #e8e8e8; color: #333; }

/* AI messages — right aligned (我方消息) */
.msg-ai { margin-left: auto; }
.msg-ai .msg-header { justify-content: flex-end; }
.msg-ai .msg-body { background: #f6ffed; border: 1px solid #b7eb8f; color: #333; }
.msg-ai.msg-draft .msg-body { background: #fffbe6; border: 1px solid #ffe58f; color: #666; }

/* Employee messages — right aligned (我方消息) */
.msg-employee { margin-left: auto; }
.msg-employee .msg-header { justify-content: flex-end; }
.msg-employee .msg-body { background: #e6f4ff; border: 1px solid #91caff; color: #333; }

/* Internal messages — centered, subtle */
.msg-internal { text-align: center; max-width: 100%; }
.msg-internal .msg-body { display: inline-block; background: #fafafa; border: 1px dashed #d9d9d9; color: #999; font-size: 12px; padding: 4px 12px; border-radius: 12px; }

/* System messages — centered */
.msg-system { text-align: center; max-width: 100%; }
.msg-system .msg-body { display: inline-block; background: #fff7e6; border: 1px solid #ffd591; color: #d46b08; font-size: 12px; padding: 4px 12px; border-radius: 12px; }

/* Media messages */
.msg-media img { max-width: 100%; max-height: 300px; border-radius: 6px; cursor: pointer; display: block; margin-top: 4px; }
.msg-media .media-link { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; background: #f5f5f5; border: 1px solid #d9d9d9; border-radius: 6px; margin-top: 4px; font-size: 13px; color: #1677ff; text-decoration: none; }
.msg-media .media-link:hover { background: #e6f4ff; }
.msg-media .media-summary { font-size: 12px; color: #999; margin-top: 4px; }
.msg-media video { max-width: 100%; max-height: 300px; border-radius: 6px; margin-top: 4px; }
.msg-media.media-video-ready .media-loading-overlay { display: none; }
.msg-caption { font-size: 13px; color: #333; margin-top: 6px; line-height: 1.5; word-break: break-word; }

/* Media download progress bar */
.media-progress-container { padding: 20px 12px; text-align: center; }
.media-progress-bar { height: 6px; background: #e8e8e8; border-radius: 3px; overflow: hidden; margin-bottom: 8px; }
.media-progress-fill { height: 100%; background: linear-gradient(90deg, #1677ff, #4096ff); border-radius: 3px; transition: width 0.2s ease; }
.media-progress-text { font-size: 12px; color: #999; }

/* Video loading overlay */
.media-loading-overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #f5f5f5; border-radius: 6px; gap: 8px; color: #999; font-size: 12px; }
.media-spinner { width: 24px; height: 24px; border: 3px solid #e8e8e8; border-top-color: #1677ff; border-radius: 50%; animation: media-spin 0.8s linear infinite; }
@keyframes media-spin { to { transform: rotate(360deg); } }

/* Media error state */
.media-error { padding: 12px; text-align: center; color: #ff4d4f; font-size: 13px; background: #fff2f0; border-radius: 6px; }

/* Translated text */
.msg-translation { margin-top: 6px; padding-top: 6px; border-top: 1px dashed #d9d9d9; font-size: 13px; color: #888; line-height: 1.5; }
.trans-tag { display: inline-block; font-size: 10px; padding: 0 4px; border: 1px solid #bbb; border-radius: 3px; color: #999; margin-right: 4px; vertical-align: middle; }
.msg-translating { border-top-color: #91caff; color: #666; }
.translating-spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid #91caff; border-top-color: #1677ff; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle; margin-right: 4px; }
.translating-text { vertical-align: middle; font-size: 12px; color: #999; }
@keyframes spin { to { transform: rotate(360deg); } }
/* Employee reply status indicators */
.msg-status { display: block; font-size: 11px; text-align: right; margin-top: 2px; }
.msg-status-sending { color: #bbb; font-style: italic; }
.msg-status-translating { color: #1677ff; font-style: italic; }
.msg-status-sent { color: #52c41a; font-weight: 500; }
.msg-status-failed { color: #ff4d4f; }
.msg-retry-btn { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-left: 4px; background: #ff4d4f; color: #fff; border-radius: 50%; font-size: 10px; font-weight: 700; cursor: pointer; line-height: 1; vertical-align: middle; transition: background 0.15s; }
.msg-retry-btn:hover { background: #ff7875; }

/* Quoted/replied message */
.msg-quote { display: flex; gap: 6px; margin-bottom: 4px; padding: 4px 0; }
.quote-line { width: 3px; background: #73d13d; border-radius: 2px; flex-shrink: 0; }
.quote-content { flex: 1; min-width: 0; }
.quote-text { font-size: 12px; color: #999; line-height: 1.5; white-space: pre-wrap; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Input area */
.chat-input { background: #fff; border-top: 1px solid #e8e8e8; padding: 6px 16px 12px; flex-shrink: 0; }
.input-status { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.input-status-right { display: flex; align-items: center; gap: 8px; }
.ai-status { font-size: 12px; padding: 2px 8px; border-radius: 10px; }
.ai-status.active { color: #52c41a; }
.ai-status.inactive { color: #faad14; }
.ai-reply-toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 12px; }
.toggle-label { color: #666; white-space: nowrap; }
.switch-small { position: relative; display: inline-block; width: 28px; height: 16px; }
.switch-small input { opacity: 0; width: 0; height: 0; }
.switch-small .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: #ccc; border-radius: 16px; transition: 0.3s; }
.switch-small .slider::before { content: ""; position: absolute; height: 12px; width: 12px; left: 2px; bottom: 2px; background: #fff; border-radius: 50%; transition: 0.3s; }
.switch-small input:checked + .slider { background: #1677ff; }
.switch-small input:checked + .slider::before { transform: translateX(12px); }
.input-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; position: relative; }
.toolbar-left { display: flex; gap: 4px; }
.toolbar-center { position: absolute; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; }
.toolbar-right { display: flex; gap: 4px; }
.btn-toolbar { background: none; border: 1px solid #d9d9d9; border-radius: 4px; width: 30px; height: 30px; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; line-height: 1; transition: all 0.2s; }
.btn-toolbar:hover { background: #f5f5f5; border-color: #1677ff; }
.btn-translate { font-size: 14px; }
.btn-translate.active { background: #e6f4ff; border-color: #1677ff; color: #1677ff; }
/* Toolbar toggle switches (AI 回复, 自动翻译) */
.toolbar-toggle { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; height: 30px; padding: 0 6px; border: 1px solid #d9d9d9; border-radius: 4px; background: none; transition: all 0.2s; }
.toolbar-toggle:hover { background: #f5f5f5; border-color: #1677ff; }
.toolbar-toggle .toggle-label { font-size: 12px; color: #666; white-space: nowrap; }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
.input-row textarea { flex: 1; resize: none; border: 1px solid #d9d9d9; border-radius: 6px; padding: 8px 12px; font-size: 14px; font-family: inherit; outline: none; }
.input-row textarea:focus { border-color: #1677ff; box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.1); }
.input-row textarea:disabled { background: #f5f5f5; cursor: not-allowed; }

/* ── Side Panel ── */
.side-panel { width: 260px; background: #fff; border-left: 1px solid #e8e8e8; overflow-y: auto; flex-shrink: 0; }
.side-panel.hidden { display: none; }
.panel-section { padding: 12px 16px; border-bottom: 1px solid #f0f0f0; }
.panel-section h4 { font-size: 13px; font-weight: 600; color: #666; margin-bottom: 8px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 13px; }
.input-small { width: 60px; height: 28px; border: 1px solid #d9d9d9; border-radius: 4px; padding: 0 6px; text-align: center; outline: none; }
.input-small:focus { border-color: #1677ff; }

/* Toggle Switch */
.switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: #ccc; border-radius: 20px; transition: 0.3s; }
.slider::before { content: ""; position: absolute; height: 14px; width: 14px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: 0.3s; }
.switch input:checked + .slider { background: #1677ff; }
.switch input:checked + .slider::before { transform: translateX(16px); }

/* Member list */
.member-list { list-style: none; }
.member-item { display: flex; align-items: center; gap: 6px; padding: 4px 0; font-size: 13px; }
.member-role { font-size: 11px; padding: 0 6px; border-radius: 3px; }
.member-admin { background: #f5222d; color: #fff; }
.member-formal_employee { background: #1677ff; color: #fff; }
.member-ai_employee { background: #52c41a; color: #fff; }
.member-customer { background: #faad14; color: #fff; }
.member-member { background: #722ed1; color: #fff; }

/* ===== WhatsApp Group Panel ===== */
.wa-group-info { font-size: 13px; color: #666; margin-bottom: 8px; line-height: 1.6; }
.wa-group-info .info-row { display: flex; justify-content: space-between; padding: 2px 0; }
.wa-group-info .info-label { color: #999; }
.wa-group-info .info-value { color: #333; font-weight: 500; }
.wa-participant-list { list-style: none; max-height: 300px; overflow-y: auto; }
.wa-participant-item { display: flex; align-items: center; gap: 8px; padding: 8px 6px; font-size: 13px; border-bottom: 1px solid #f0f0f0; cursor: pointer; border-radius: 4px; transition: background 0.15s; }
.wa-participant-item:hover { background: #f5f7fa; }
.wa-participant-item:last-child { border-bottom: none; }
.wa-participant-name { font-weight: 500; color: #222; }
.wa-participant-jid { font-size: 11px; color: #999; margin-left: auto; }
.wa-participant-badge { font-size: 11px; padding: 1px 6px; border-radius: 3px; background: #f0f0f0; color: #666; white-space: nowrap; margin-left: 4px; }

/* ===== WhatsApp 成员弹窗 ===== */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-overlay.hidden { display: none; }
.modal-content { background: #fff; border-radius: 12px; width: 90%; max-width: 380px; box-shadow: 0 8px 40px rgba(0,0,0,0.15); overflow: hidden; animation: modalIn 0.2s ease; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.modal-header h4 { font-size: 16px; font-weight: 600; color: #333; margin: 0; }
.modal-close { background: none; border: none; font-size: 24px; color: #999; cursor: pointer; padding: 0 4px; line-height: 1; }
.modal-close:hover { color: #333; }
.modal-body { padding: 16px 20px; }
.modal-footer { padding: 12px 20px 16px; text-align: center; }
.modal-footer .btn-primary { width: 100%; padding: 10px; font-size: 15px; }

.wa-profile { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid #f0f0f0; }
.wa-profile-avatar { width: 48px; height: 48px; border-radius: 50%; background: #1677ff; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 600; flex-shrink: 0; }
.wa-profile-info { flex: 1; min-width: 0; }
.wa-profile-name { font-size: 16px; font-weight: 600; color: #222; }
.wa-profile-phone { font-size: 12px; color: #999; margin-top: 2px; word-break: break-all; }
.wa-profile-role { margin-top: 4px; }
.wa-profile-role .member-role { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 4px; background: #e6f4ff; color: #1677ff; }

.wa-detail-grid { display: flex; flex-direction: column; gap: 8px; }
.wa-detail-grid .detail-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 13px; }
.wa-detail-grid .detail-label { color: #999; }
.wa-detail-grid .detail-value { color: #333; font-weight: 500; }

/* ===== Admin Pages ===== */
.admin-main { flex: 1; overflow-y: auto; padding: 24px; }
.admin-nav { display: flex; background: #fff; border-bottom: 1px solid #e8e8e8; flex-shrink: 0; padding: 0 24px; }
.admin-nav-item { padding: 12px 20px; font-size: 14px; color: #666; border-bottom: 2px solid transparent; transition: all 0.2s; }
.admin-nav-item:hover { color: #1677ff; }
.admin-nav-item.active { color: #1677ff; border-bottom-color: #1677ff; font-weight: 600; }

.admin-section { background: #fff; border-radius: 8px; padding: 20px 24px; margin-bottom: 20px; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-header h2 { font-size: 18px; font-weight: 600; }
.admin-desc { font-size: 13px; color: #999; margin-bottom: 16px; line-height: 1.5; }

/* Config section */
.config-section { margin-bottom: 20px; }
.config-section .section-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.config-card { padding: 16px; border: 1px solid #e8e8e8; border-radius: 8px; margin-bottom: 12px; }
.config-card.config-card-disabled { opacity: 0.55; background: #fafafa; }
.config-card.config-card-disabled .checkbox-label { cursor: not-allowed; color: #aaa; }
.config-card.config-card-disabled input[type="checkbox"] { cursor: not-allowed; }
.config-card-row { display: flex; align-items: center; margin-bottom: 8px; }
.config-card-desc { font-size: 13px; color: #888; margin-bottom: 8px; padding: 0 2px; }
.config-card-controls { padding: 4px 2px 0; }
.config-sub-area { padding: 12px; border-radius: 6px; background: #fafafa; margin-top: 8px; transition: opacity 0.2s; }
.config-sub-area.disabled { opacity: 0.5; pointer-events: none; }
.config-sub-label { font-size: 13px; font-weight: 500; color: #555; margin-bottom: 8px; }
.config-sub-item { margin-top: 10px; padding-top: 10px; border-top: 1px solid #e8e8e8; }
.config-sub-item .hint-text { display: block; margin-top: 4px; }
.config-sub-area .radio-label { margin-right: 20px; cursor: pointer; font-size: 13px; }
.config-sub-area .radio-label input { margin-right: 4px; }

/* Admin table */
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th { padding: 10px 12px; text-align: left; font-weight: 600; font-size: 13px; color: #666; border-bottom: 2px solid #e8e8e8; }
.admin-table td { padding: 10px 12px; border-bottom: 1px solid #f0f0f0; font-size: 13px; }
.admin-table tr:hover td { background: #fafafa; }

/* Channel cards */
.channel-card { border: 1px solid #e8e8e8; border-radius: 8px; margin-bottom: 12px; overflow: hidden; }
.channel-card-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: #fafafa; border-bottom: 1px solid #e8e8e8; }
.channel-card-title { font-size: 14px; font-weight: 600; }
.channel-card-actions { display: flex; align-items: center; gap: 8px; }
.channel-card-body { padding: 16px; }

/* Channel tag */
.channel-tag { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 3px; margin-right: 2px; vertical-align: middle; line-height: 1.4; }
.channel-tag.WA { background: #e6f7ff; color: #1890ff; border: 1px solid #91d5ff; }
.channel-tag.WX { background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
.channel-tag.QWX { background: #fff7e6; color: #fa8c16; border: 1px solid #ffd591; }

/* Loading / Error / Hint */
.loading-msg { padding: 20px; text-align: center; color: #999; font-size: 14px; }
.error-msg { padding: 20px; text-align: center; color: #ff4d4f; font-size: 14px; }
.hint-text { font-size: 12px; color: #999; }

/* Modals */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 500; }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 440px; max-width: 90vw; background: #fff; border-radius: 12px; padding: 24px; z-index: 501; max-height: 80vh; overflow-y: auto; box-shadow: 0 8px 40px rgba(0,0,0,0.15); }
.modal h3 { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal .form-actions { margin-top: 20px; }
.input-full { width: 100%; height: 36px; padding: 0 10px; border: 1px solid #d9d9d9; border-radius: 4px; font-size: 13px; outline: none; }
.input-full:focus { border-color: #1677ff; }
select.input-full { background: #fff; }
.hidden { display: none !important; }

/* Radio group */
.radio-group { display: flex; gap: 16px; flex-wrap: wrap; }
.radio-label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; font-size: 13px; }

/* Checkbox label */
.checkbox-label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; }
.checkbox-label-large { font-size: 14px; }
.checkbox-label input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* Employee select */
.employee-select { max-height: 150px; overflow-y: auto; }
.employee-select .checkbox-label { display: block; padding: 4px 0; }

/* Status dot */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.active { background: #52c41a; }
.status-dot.inactive { background: #d9d9d9; }

/* Text colors */
.text-danger { color: #ff4d4f !important; }
.text-danger:hover { color: #ff7875 !important; }

/* ===== Task List ===== */
.task-item { padding: 8px 0; cursor: pointer; border-bottom: 1px solid #f5f5f5; }
.task-item:last-child { border-bottom: none; }
.task-item-header { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.task-name { flex: 1; font-weight: 500; }
.task-status-tag { font-size: 10px; padding: 1px 6px; border-radius: 8px; }
.task-status-pending { background: #f5f5f5; color: #999; }
.task-status-in_progress { background: #e6f7ff; color: #1890ff; }
.task-status-completed { background: #f6ffed; color: #52c41a; }
.task-status-failed { background: #fff2f0; color: #ff4d4f; }
.task-status-blocked { background: #fff7e6; color: #fa8c16; }
.task-progress { font-size: 11px; color: #999; }
.task-progress-bar { height: 4px; background: #f0f0f0; border-radius: 2px; margin: 6px 0; overflow: hidden; }
.task-progress-fill { height: 100%; background: #1677ff; border-radius: 2px; transition: width 0.3s; }
.task-subtasks { display: none; padding: 6px 0 2px 12px; }
.task-subtasks.expanded { display: block; }
.task-subtask { display: flex; align-items: center; gap: 4px; font-size: 12px; padding: 3px 0; color: #666; }
.task-status-icon { width: 14px; text-align: center; font-size: 11px; }
.task-status-icon.task-status-completed { color: #52c41a; }
.task-status-icon.task-status-in_progress { color: #1890ff; }
.task-status-icon.task-status-pending { color: #bfbfbf; }
.task-status-icon.task-status-failed { color: #ff4d4f; }
.task-status-icon.task-status-blocked { color: #fa8c16; }
.task-subtask-value { color: #999; }

/* ===== Tag Badges ===== */
.tag-badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 10px; color: #fff; margin: 2px 2px; line-height: 1.6; }
.tag-add-btn { display: inline-block; font-size: 12px; color: #1677ff; cursor: pointer; padding: 2px 6px; border: 1px dashed #91caff; border-radius: 10px; margin: 2px; }
.tag-add-btn:hover { background: #e6f4ff; }
.tag-select-popup { background: #fff; border: 1px solid #e8e8e8; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.12); padding: 8px; z-index: 600; min-width: 140px; }
.tag-option { padding: 6px 8px; cursor: pointer; border-radius: 4px; display: flex; align-items: center; gap: 6px; font-size: 13px; }
.tag-option:hover { background: #f5f5f5; }
.tag-option.active { background: #f0f7ff; }

/* ===== Rating Stars ===== */
.rating-star { font-size: 20px; color: #e8e8e8; cursor: pointer; transition: color 0.15s; }
.rating-star.filled { color: #fadb14; }
.rating-star:hover { color: #fadb14; }
.rating-stars.rating-readonly { pointer-events: none; color: #fadb14; }

/* ===== Customer Info ===== */
.customer-section { margin-top: 8px; }
.customer-section-label { font-size: 12px; font-weight: 600; color: #888; margin-bottom: 4px; }
.remark-label { font-size: 12px; font-weight: 600; color: #888; }
.remark-text { font-size: 12px; color: #1677ff; cursor: pointer; }
.remark-input { width: 100%; font-size: 12px; padding: 2px 6px; border: 1px solid #d9d9d9; border-radius: 4px; outline: none; }
.remark-input:focus { border-color: #1677ff; }

/* ===== Audit Suggestions ===== */
.audit-suggestions { margin-bottom: 6px; }
.audit-card { background: #fffbe6; border: 1px solid #ffe58f; border-radius: 8px; padding: 10px 12px; margin-bottom: 6px; animation: auditSlideIn 0.2s ease-out; }
@keyframes auditSlideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
.audit-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.audit-card-title { font-size: 12px; font-weight: 600; color: #d46b08; }
.audit-card-timer { font-size: 11px; color: #d46b08; font-weight: 600; }
.audit-card-body { margin-bottom: 6px; }
.audit-text { background: #fff; border: 1px solid #d9d9d9; border-radius: 4px; padding: 6px 8px; font-size: 13px; min-height: 32px; outline: none; white-space: pre-wrap; }
.audit-text:focus { border-color: #1677ff; }
.audit-file-info { padding: 4px 0; font-size: 13px; color: #333; }
.audit-card-actions { display: flex; gap: 6px; }
.audit-card-actions .btn-sm { margin: 0; }

/* ===== Group list preview and meta ===== */
.group-item-meta { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.group-item-preview { color: #999; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.group-item-time { color: #bbb; flex-shrink: 0; margin-left: 8px; }

/* ===== Message avatar layout ===== */
.msg { display: flex; gap: 8px; margin-bottom: 16px; }
.msg-customer { flex-direction: row; }
.msg-ai, .msg-employee { flex-direction: row-reverse; }
.msg-avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; flex-shrink: 0; }
.msg-avatar-customer { background: #e8e8e8; color: #666; }
.msg-avatar-ai { background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
.msg-avatar-employee { background: #e6f4ff; color: #1677ff; border: 1px solid #91caff; }
.msg-content { min-width: 0; max-width: 75%; }
.msg-customer .msg-content { text-align: left; }
.msg-ai .msg-content, .msg-employee .msg-content { text-align: left; }

/* ===== Contact Book ===== */
.contact-filters { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid #f0f0f0; }
.contact-filter-select { flex: 1; height: 28px; padding: 0 4px; border: 1px solid #d9d9d9; border-radius: 4px; font-size: 12px; outline: none; background: #fff; }
.contact-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; cursor: pointer; border-bottom: 1px solid #f5f5f5; transition: background 0.15s; }
.contact-item:hover { background: #f5f5f5; }
.contact-avatar { width: 36px; height: 36px; border-radius: 50%; background: #e6f4ff; color: #1677ff; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.contact-info { flex: 1; min-width: 0; }
.contact-name { font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.contact-meta { font-size: 12px; color: #999; }
.contact-tags { margin-top: 2px; }
.contact-book-btn.active { background: #e6f4ff; border-color: #1677ff; }

/* ===== Search Panel ===== */
.search-panel { background: #fff; border-left: 1px solid #e8e8e8; width: 320px; flex-shrink: 0; display: flex; flex-direction: column; }
.search-panel-header { padding: 12px 16px; border-bottom: 1px solid #e8e8e8; }
.search-panel-header h4 { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.search-panel-header input { width: 100%; height: 32px; padding: 0 8px; border: 1px solid #d9d9d9; border-radius: 4px; font-size: 13px; outline: none; }
.search-panel-header input:focus { border-color: #1677ff; }
.search-panel-results { flex: 1; overflow-y: auto; }
.search-result-item { padding: 10px 16px; cursor: pointer; border-bottom: 1px solid #f5f5f5; font-size: 13px; }
.search-result-item:hover { background: #f5f5f5; }
.search-result-item.active { background: #e6f4ff; }
.search-result-match em { background: #fff3cd; font-style: normal; padding: 0 2px; border-radius: 2px; }
.search-result-context { color: #999; font-size: 11px; margin-top: 2px; }
.search-result-time { font-size: 11px; color: #bbb; margin-left: 8px; }

/* ===== Search highlight pulse ===== */
@keyframes highlightPulse {
    0%, 100% { background-color: transparent; }
    50% { background-color: #fff3cd; }
}
.msg-highlight { animation: highlightPulse 2s ease-in-out 3; }

/* ── 系统状态指示器 ── */
.status-dot { font-size: 16px; cursor: pointer; margin-right: 8px; }
.status-ok { color: #52c41a; }
.status-err { color: #ff4d4f; }

/* ===== Dropdown Menu (sidebar +) ===== */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu { position: absolute; z-index: 800; min-width: 160px; background: #fff; border: 1px solid #e8e8e8; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.12); padding: 4px 0; }
.dropdown-menu.hidden { display: none; }
.dropdown-up .dropdown-menu { bottom: 100%; left: 0; margin-bottom: 4px; }
.dropdown-down .dropdown-menu { top: 100%; left: 0; margin-top: 4px; }
.dropdown-item { display: flex; align-items: center; gap: 8px; padding: 10px 16px; font-size: 14px; color: #333; cursor: pointer; white-space: nowrap; transition: background 0.15s; }
.dropdown-item:hover { background: #f5f7fa; }
.dropdown-item:first-child { border-radius: 8px 8px 0 0; }
.dropdown-item:last-child { border-radius: 0 0 8px 8px; }

/* ===== Action Modal (添加联系人 / 创建群组) ===== */
.modal-form .form-group { margin-bottom: 16px; }
.modal-form .form-group label { display: block; font-size: 13px; font-weight: 500; color: #555; margin-bottom: 6px; }
.modal-form .input-full { width: 100%; height: 40px; padding: 0 12px; border: 1px solid #d9d9d9; border-radius: 6px; font-size: 14px; outline: none; transition: border-color 0.2s; }
.modal-form .input-full:focus { border-color: #1677ff; box-shadow: 0 0 0 2px rgba(22,119,255,0.1); }
.modal-form .hint-text { display: block; font-size: 12px; color: #999; margin-top: 4px; }
.modal-form .form-error { color: #ff4d4f; font-size: 13px; margin-bottom: 12px; padding: 8px 12px; background: #fff2f0; border: 1px solid #ffccc7; border-radius: 6px; display: none; }
.modal-form .btn-primary { width: 100%; height: 40px; background: #1677ff; color: #fff; border: none; border-radius: 6px; font-size: 15px; font-weight: 500; cursor: pointer; transition: background 0.2s; }
.modal-form .btn-primary:hover { background: #4096ff; }
.modal-form .btn-primary:disabled { background: #a0c4ff; cursor: not-allowed; }
.modal-form .btn-secondary { width: 100%; height: 40px; background: #fff; color: #333; border: 1px solid #d9d9d9; border-radius: 6px; font-size: 15px; cursor: pointer; transition: border-color 0.2s; }
.modal-form .btn-secondary:hover { border-color: #1677ff; color: #1677ff; }
.modal-form .form-actions { display: flex; gap: 8px; margin-top: 20px; }
.modal-form .form-actions .btn-primary,
.modal-form .form-actions .btn-secondary { flex: 1; }

/* ===== Message "more" button ===== */
.msg-more-btn { display: inline-flex; align-items: center; justify-content: center; background: none; border: none; color: #bbb; cursor: pointer; font-size: 16px; font-weight: 700; padding: 0 2px; line-height: 1; border-radius: 3px; transition: all 0.15s; vertical-align: middle; }
.msg-more-btn:hover { color: #1677ff; background: #f0f0f0; }
/* 客户消息 header 是 flex-start，按钮 margin-left:auto 推到右边缘 */
.msg-customer .msg-header .msg-more-btn { margin-left: auto; }
.msg-wrapper { position: relative; }

/* ===== Message Context Menu (回复/转发) ===== */
.msg-context-menu { position: absolute; z-index: 900; min-width: 140px; background: #fff; border: 1px solid #e8e8e8; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.15); padding: 4px 0; display: none; }
.msg-context-menu.visible { display: block; }
.msg-context-item { display: flex; align-items: center; gap: 8px; padding: 10px 16px; font-size: 13px; color: #333; cursor: pointer; transition: background 0.15s; }
.msg-context-item:hover { background: #f5f7fa; }
.msg-context-item:first-child { border-radius: 8px 8px 0 0; }
.msg-context-item:last-child { border-radius: 0 0 8px 8px; }
.msg-wrapper { position: relative; }

/* ===== Forward Mode (多选转发) ===== */
.forward-bar { display: none; align-items: center; justify-content: space-between; padding: 8px 16px; background: #e6f4ff; border-bottom: 1px solid #91caff; flex-shrink: 0; }
.forward-bar.visible { display: flex; }
.forward-bar-info { font-size: 13px; color: #1677ff; font-weight: 500; }
.forward-bar-actions { display: flex; gap: 8px; }
.forward-bar .btn-primary { height: 32px; padding: 0 16px; background: #1677ff; color: #fff; border: none; border-radius: 4px; font-size: 13px; cursor: pointer; }
.forward-bar .btn-primary:hover { background: #4096ff; }
.forward-bar .btn-secondary { height: 32px; padding: 0 16px; background: #fff; color: #333; border: 1px solid #d9d9d9; border-radius: 4px; font-size: 13px; cursor: pointer; }
.forward-bar .btn-secondary:hover { border-color: #1677ff; color: #1677ff; }
.msg-forward-check { display: none; position: absolute; top: 4px; left: 4px; z-index: 5; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #1677ff; background: #fff; cursor: pointer; align-items: center; justify-content: center; font-size: 12px; color: #fff; }
.msg-forward-check.visible { display: flex; }
.msg-forward-check.checked { background: #1677ff; }
.msg-forward-check.checked::after { content: "✓"; }
.forward-mode .msg-forward-check { display: flex; }

/* ============================================================
   WhatsApp 风格添加联系人 & 创建群组弹窗
   ============================================================ */
.required { color: #ff4d4f; }

.phone-input-group {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.country-code-select {
  width: 130px;
  min-width: 130px;
  height: 40px;
  padding: 0 8px;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  cursor: pointer;
  outline: none;
}
.country-code-select:focus {
  border-color: #1677ff;
  box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.1);
}
.phone-number-input {
  flex: 1;
  height: 40px !important;
}

.form-status {
  display: none;
  font-size: 13px;
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: 6px;
}
.form-status.visible { display: block; }
.form-status.info    { background: #e6f7ff; border: 1px solid #91d5ff; color: #1890ff; }
.form-status.success { background: #f6ffed; border: 1px solid #b7eb8f; color: #52c41a; }
.form-status.warning { background: #fffbe6; border: 1px solid #ffe58f; color: #faad14; }
.form-status.error   { background: #fff2f0; border: 1px solid #ffccc7; color: #ff4d4f; }

.contact-picker-section {
  margin-bottom: 4px;
}
.contact-picker-section-title {
  font-size: 12px;
  font-weight: 600;
  color: #999;
  padding: 8px 12px 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.contact-picker-list {
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid #e8e8e8;
  border-radius: 8px;
  margin-top: 8px;
}
.contact-picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f5f5f5;
  transition: background 0.15s;
}
.contact-picker-item:last-child { border-bottom: none; }
.contact-picker-item:hover { background: #f5f7fa; }
.contact-picker-item.selected { background: #e6f7ff; }
.contact-picker-checkbox {
  width: 18px;
  height: 18px;
  accent-color: #1677ff;
  cursor: pointer;
  flex-shrink: 0;
}
.contact-picker-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #1677ff;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}
.contact-picker-avatar.employee { background: #52c41a; }
.contact-picker-avatar.phonebook { background: #1677ff; }
.contact-picker-info { flex: 1; min-width: 0; }
.contact-picker-name {
  font-size: 14px;
  font-weight: 500;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.contact-picker-role,
.contact-picker-phone {
  font-size: 12px;
  color: #999;
  margin-top: 1px;
}
.contact-picker-meta {
  font-size: 12px;
  color: #999;
  margin-top: 2px;
}
.contact-picker-empty {
  padding: 24px;
  text-align: center;
  color: #999;
  font-size: 14px;
}
.contact-picker-wrapper {
  margin-top: 8px;
}
.contact-picker-footer {
  display: flex;
  justify-content: flex-end;
  padding: 6px 0;
}
.selected-count {
  font-size: 13px;
  color: #999;
}
.modal-participant-count {
  font-size: 12px;
  color: #999;
  font-weight: normal;
  margin-left: 8px;
}

/* ===== Tenant Branding — Login Page ===== */
.login-system-brand {
    position: fixed;
    top: 16px;
    left: 24px;
    font-size: 14px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    letter-spacing: 1px;
    z-index: 10;
    user-select: none;
}
.login-tenant-brand {
    text-align: center;
    margin-bottom: 24px;
}
.login-tenant-logo {
    max-width: 180px;
    max-height: 80px;
    object-fit: contain;
    margin: 0 auto 12px;
    display: block;
}
.login-tenant-name {
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* ===== Admin — Branding Settings Page ===== */
.branding-preview {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    padding: 32px;
    margin-bottom: 24px;
    text-align: center;
    position: relative;
    min-height: 160px;
}
.branding-preview-header {
    position: absolute;
    top: 12px;
    left: 16px;
}
.branding-preview-system {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 1px;
}
.branding-preview-body {
    padding-top: 16px;
}
.branding-preview-logo {
    max-width: 160px;
    max-height: 72px;
    object-fit: contain;
    margin: 0 auto 12px;
}
.branding-preview-name {
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
.logo-upload-area {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.logo-upload-hint {
    font-size: 12px;
    color: #999;
}
.logo-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    width: 100%;
}
.logo-preview img {
    max-width: 120px;
    max-height: 60px;
    object-fit: contain;
    border: 1px solid #e8e8e8;
    border-radius: 4px;
    padding: 4px;
}
.save-status {
    font-size: 13px;
    margin-left: 12px;
}
.save-success { color: #52c41a; }
.save-error { color: #ff4d4f; }
.form-input {
    width: 100%;
    max-width: 400px;
    height: 36px;
    padding: 0 12px;
    border: 1px solid #d9d9d9;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.form-input:focus {
    border-color: #1677ff;
    box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.1);
}
