/* 全局重置与移动端优化 */
*, *::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, sans-serif;
  background: #f0f2f5;
  color: #333;
  -webkit-text-size-adjust: 100%;
}
:root {
  --primary: #07c160;
  --primary-dark: #06ad56;
  --danger: #fa5151;
  --bg: #f0f2f5;
  --bubble-visitor: #fff;
  --bubble-admin: #95ec69;
  --header-h: 48px;
  --input-h: 56px;
}

/* ========== 访客端 ========== */
.visitor-app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  background: #ededed;
}
.header {
  height: var(--header-h);
  background: #ededed;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 17px;
  border-bottom: 1px solid #ddd;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.msg {
  display: flex;
  margin-bottom: 12px;
  max-width: 80%;
}
.msg.visitor { margin-left: auto; flex-direction: row-reverse; }
.msg.admin { margin-right: auto; }
.bubble {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
}
.msg.visitor .bubble { background: var(--bubble-admin); border-top-right-radius: 2px; }
.msg.admin .bubble { background: var(--bubble-visitor); border-top-left-radius: 2px; }
.bubble img {
  max-width: 200px;
  max-height: 200px;
  border-radius: 4px;
  display: block;
  cursor: pointer;
}
.file-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}
.file-card a { color: #576b95; text-decoration: none; font-size: 14px; }
.time {
  font-size: 11px;
  color: #999;
  text-align: center;
  margin: 8px 0;
}
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  background: #f7f7f7;
  border-top: 1px solid #ddd;
  flex-shrink: 0;
  min-height: var(--input-h);
}
.input-bar textarea {
  flex: 1;
  border: none;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 16px;
  resize: none;
  max-height: 100px;
  line-height: 1.4;
  background: #fff;
  outline: none;
}
.btn-icon {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  flex-shrink: 0;
}
.btn-send {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0 16px;
  height: 40px;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-send:disabled { opacity: .5; }
.login-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  padding: 20px;
  background: #fff;
}
.login-box input {
  width: 100%;
  max-width: 280px;
  height: 44px;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 0 14px;
  font-size: 16px;
  margin-bottom: 16px;
}
.login-box button {
  width: 100%;
  max-width: 280px;
  height: 44px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
}
.ended-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  color: #fff;
  font-size: 18px;
  text-align: center;
  padding: 20px;
}

/* ========== 客服端 ========== */
.admin-app {
  display: flex;
  height: 100dvh;
  background: #fff;
}
.sidebar {
  width: 280px;
  border-right: 1px solid #e5e5e5;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: #fafafa;
}
.sidebar-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-weight: 600;
  border-bottom: 1px solid #e5e5e5;
}
.session-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.session-item {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  position: relative;
}
.session-item:hover, .session-item.active { background: #e8f5e9; }
.session-item .name { font-weight: 500; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .badge {
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}
.session-item .offline { opacity: .5; }
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid #e5e5e5;
  font-weight: 600;
  gap: 12px;
}
.chat-header .back-btn {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}
.btn-destroy {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 15px;
}

/* 客服手机端：列表与聊天切换 */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    position: absolute;
    inset: 0;
    z-index: 20;
    transition: transform .25s ease;
  }
  .sidebar.hide { transform: translateX(-100%); }
  .chat-panel {
    width: 100%;
  }
  .chat-header .back-btn { display: block; }
  .btn-destroy { font-size: 12px; padding: 5px 10px; }
}

/* 图片放大层 */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: zoom-out;
}
.lightbox.show { display: flex; }
.lightbox img {
  max-width: 95%;
  max-height: 95%;
  object-fit: contain;
}
