/* ===== 全局 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --success: #10B981;
  --danger: #EF4444;
  --bg: #F3F4F6;
  --white: #FFFFFF;
  --text: #1F2937;
  --text-secondary: #6B7280;
  --border: #E5E7EB;
  --bubble-customer: #4F46E5;
  --bubble-admin: #F3F4F6;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

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

/* ===== 入口屏 ===== */
.entry-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.entry-box {
  background: var(--white);
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.entry-logo {
  font-size: 56px;
  margin-bottom: 12px;
}
.entry-box h1 {
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--text);
}
.entry-box p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  font-size: 14px;
}
.entry-box input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 16px;
}
.entry-box input:focus {
  border-color: var(--primary);
}
.entry-box button {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s;
}
.entry-box button:hover {
  background: var(--primary-hover);
}
.login-hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ===== 聊天屏 ===== */
.chat-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 800px;
  margin: 0 auto;
  background: var(--white);
  box-shadow: var(--shadow);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.header-title {
  font-size: 16px;
  font-weight: 700;
}
.header-status {
  font-size: 12px;
  color: var(--success);
}
.header-status.offline {
  color: var(--text-secondary);
}

/* ===== 消息区 ===== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #FAFBFC;
}
.chat-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: #D1D5DB;
  border-radius: 3px;
}

/* 消息气泡 */
.msg-row {
  display: flex;
  max-width: 75%;
  animation: msgIn 0.25s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg-row.customer {
  align-self: flex-end;
}
.msg-row.admin {
  align-self: flex-start;
}
.msg-row.system {
  align-self: center;
  max-width: 90%;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  position: relative;
}
.msg-row.customer .msg-bubble {
  background: var(--bubble-customer);
  color: white;
  border-bottom-right-radius: 4px;
}
.msg-row.admin .msg-bubble {
  background: var(--bubble-admin);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.msg-row.system .msg-bubble {
  background: #E5E7EB;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 10px;
}

.msg-sender {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 2px;
  padding: 0 4px;
}
.msg-time {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 4px;
  opacity: 0.7;
}
.msg-row.customer .msg-time {
  color: rgba(255,255,255,0.7);
}

/* 图片消息 */
.msg-image {
  max-width: 250px;
  max-height: 250px;
  border-radius: 8px;
  cursor: pointer;
  display: block;
}
.msg-image-wrap {
  position: relative;
}
.msg-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(0,0,0,0.05);
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
}
.msg-row.customer .msg-file {
  background: rgba(255,255,255,0.2);
  color: white;
}
.msg-file-icon {
  font-size: 24px;
}

/* ===== 输入区 ===== */
.chat-input-area {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--white);
  flex-shrink: 0;
}
.input-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.tool-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  transition: background 0.15s;
}
.tool-btn:hover {
  background: var(--bg);
}
.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.input-row textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 16px;
  outline: none;
  resize: none;
  max-height: 120px;
  font-family: inherit;
  line-height: 1.4;
}
.input-row textarea:focus {
  border-color: var(--primary);
}
.input-row button {
  width: 64px;
  height: 40px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
  flex-shrink: 0;
  transition: background 0.2s;
}
.input-row button:hover {
  background: var(--primary-hover);
}

/* ===== 图片预览 ===== */
.image-preview-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.image-preview-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
}
.image-preview-close {
  position: absolute;
  top: 20px;
  right: 30px;
  font-size: 40px;
  color: white;
  cursor: pointer;
}

/* ===== 管理员登录 ===== */
.admin-login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #1e3a5f 0%, #2d1b4e 100%);
}
.admin-login-box {
  background: var(--white);
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.admin-login-box input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
}
.admin-login-box input:focus {
  border-color: var(--primary);
}
.admin-login-box button {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  cursor: pointer;
  font-weight: 600;
  margin-top: 4px;
}

/* ===== 客服面板 ===== */
.admin-panel {
  display: flex;
  height: 100vh;
}
.admin-sidebar {
  width: 320px;
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.admin-sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.admin-sidebar-header h2 {
  font-size: 18px;
  margin-bottom: 8px;
}
.admin-user-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
}
.conversation-list {
  flex: 1;
  overflow-y: auto;
}
.conversation-list::-webkit-scrollbar {
  width: 4px;
}
.conversation-list::-webkit-scrollbar-thumb {
  background: #D1D5DB;
  border-radius: 2px;
}
.conv-item {
  padding: 14px 20px;
  border-bottom: 1px solid #F3F4F6;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.conv-item:hover {
  background: #F9FAFB;
}
.conv-item.active {
  background: #EEF2FF;
  border-left: 3px solid var(--primary);
}
.conv-item-name {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.conv-item-last {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item-badge {
  background: var(--danger);
  color: white;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 600;
}
.conv-item-time {
  font-size: 11px;
  color: var(--text-secondary);
}
.conv-closed {
  opacity: 0.5;
}
.conv-online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 4px;
  flex-shrink: 0;
}
.conv-online-dot.online { background: #10B981; box-shadow: 0 0 0 2px rgba(16,185,129,0.2); }
.conv-online-dot.offline { background: #D1D5DB; }

/* 标签页 */
.conv-tabs {
  display: flex;
  gap: 0;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: #FAFBFC;
}
.conv-tab {
  flex: 1;
  padding: 7px 0;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.15s;
  text-align: center;
}
.conv-tab:hover {
  background: #EEF2FF;
  color: var(--primary);
}
.conv-tab.active {
  background: var(--primary);
  color: white;
  font-weight: 600;
}
.empty-hint {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
  font-size: 14px;
}
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.admin-chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--white);
}
.no-conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  gap: 12px;
}
.admin-chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ===== 按钮 ===== */
.btn-sm {
  padding: 4px 12px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}
.btn-sm:hover {
  background: var(--bg);
}
.btn-danger-sm {
  padding: 6px 14px;
  font-size: 12px;
  border: 1px solid var(--danger);
  background: var(--white);
  color: var(--danger);
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-danger-sm:hover {
  background: var(--danger);
  color: white;
}
.btn-primary {
  padding: 8px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.btn-secondary {
  padding: 8px 20px;
  background: var(--bg);
  color: var(--text);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

/* ===== 弹窗 ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}
.modal-box {
  background: var(--white);
  padding: 28px;
  border-radius: 16px;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-box h3 {
  margin-bottom: 16px;
}
.modal-box input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 10px;
  outline: none;
}
.modal-box input:focus {
  border-color: var(--primary);
}
.modal-btns {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .admin-sidebar { width: 100%; position: absolute; z-index: 10; height: 100%; left: -100%; transition: left 0.3s; }
  .admin-sidebar.open { left: 0; }
  .chat-screen { max-width: 100%; }
}

/* 上传进度 */
.upload-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: var(--primary);
  border-radius: 0 0 16px 16px;
  animation: uploadPulse 0.8s infinite;
}
@keyframes uploadPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
