/* ====================================================================
 * 轻量级客服系统 —— 全站样式（极简、清爽、PC / 手机自适应）
 * 不依赖任何 UI 框架，纯原生 CSS。
 * ==================================================================== */

:root {
  --primary: #ffc53d;        /* 主色：亮黄（左面板 / 发送按钮） */
  --primary-dark: #f0a92a;   /* 主色加深（悬停） */
  --primary-soft: #fff6dd;   /* 主色浅染（后台悬停等） */
  --bg: #edeff2;             /* 浅灰背景（卡片悬浮其上） */
  --panel: #ffffff;
  --text: #1f2330;
  --muted: #8a90a2;
  --border: #e6e8ef;
  --self: #2d5be3;           /* 自己（用户）消息气泡：深蓝色 */
  --other: #f2f3f5;          /* 对方（客服）消息气泡：浅灰色 */
  --danger: #e5484d;
  --radius: 12px;
  --shadow: 0 18px 50px rgba(31, 35, 48, .14);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; cursor: pointer; border: none; }
input, textarea { font-family: inherit; font-size: 14px; }

/* ===================== 登录页 ===================== */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-box {
  width: 100%; max-width: 340px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 28px 24px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.login-box h2 { text-align: center; font-size: 20px; margin-bottom: 6px; }
.login-box input {
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; outline: none;
  transition: border-color .15s;
}
.login-box input:focus { border-color: var(--primary); }
.login-box button {
  padding: 12px; background: var(--primary); color: #fff; border-radius: 10px;
  font-weight: 600; font-size: 15px; transition: background .15s;
}
.login-box button:hover { background: var(--primary-dark); }
.login-msg { color: var(--danger); text-align: center; font-size: 13px; min-height: 18px; }
.login-tip { color: var(--muted); font-size: 12px; text-align: center; }

/* ===================== 通用按钮 ===================== */
.mini-btn {
  padding: 6px 12px; border: 1px solid var(--border); background: #fff;
  border-radius: 8px; font-size: 13px; color: var(--text); transition: .15s;
}
.mini-btn:hover { border-color: var(--primary); color: var(--primary); }
.mini-btn.danger { color: var(--danger); border-color: #f3c2c4; }
.mini-btn.danger:hover { background: #fdeced; border-color: var(--danger); }

/* ===================== 访客端聊天（左右分栏弹窗） ===================== */
.chat-app {
  display: flex; width: min(900px, 94vw); height: min(640px, 90vh);
  margin: 5vh auto; background: var(--panel); border-radius: 20px;
  box-shadow: var(--shadow); overflow: hidden;
}

/* ---- 左侧品牌面板（纯色亮黄） ---- */
.brand-panel {
  flex: 0 0 280px; display: flex; flex-direction: column; align-items: center;
  padding: 40px 26px; text-align: center; color: #3a2f00;
  background: var(--primary);
  background: linear-gradient(160deg, #ffd24a 0%, #ffc53d 55%, #f7b429 100%);
}
.brand-ava {
  width: 96px; height: 96px; border-radius: 50%; overflow: hidden; flex: 0 0 auto;
  background: #fff; border: 4px solid #fff; box-shadow: 0 6px 18px rgba(0,0,0,.12);
  display: flex; align-items: center; justify-content: center;
}
.brand-ava img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-name { font-size: 19px; font-weight: 700; margin-top: 18px; letter-spacing: .5px; }
.brand-desc { font-size: 13px; line-height: 1.6; margin-top: 10px; color: #6b5a1a; max-width: 220px; }
.brand-feats { list-style: none; margin-top: 22px; display: flex; flex-direction: column; gap: 12px; text-align: left; }
.brand-feats li { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: #4a3d12; }
.brand-feats .ck {
  flex: 0 0 auto; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; color: #f0a92a; display: flex; align-items: center; justify-content: center;
}
.brand-feats .ck svg { width: 12px; height: 12px; display: block; }

/* ---- 右侧聊天主区 ---- */
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }
.chat-header {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.chat-header .ava {
  width: 38px; height: 38px; border-radius: 50%; background: var(--other);
  color: #1f2330; display: flex; align-items: center; justify-content: center; font-weight: 700;
  overflow: hidden; flex: 0 0 auto;
}
.chat-header .ava img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hinfo { flex: 1; min-width: 0; }
.hname { font-weight: 600; }
.hstatus { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.hstatus .dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; }
.nick-btn { font-size: 12px; color: #b98900; background: none; border: 1px solid #f0dca0; border-radius: 8px; padding: 5px 10px; }
.nick-btn:hover { border-color: var(--primary-dark); }

.chat-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; background: #fff; }

.msg { display: flex; gap: 8px; max-width: 80%; }
.msg.self { align-self: flex-end; flex-direction: row-reverse; }
.msg.other { align-self: flex-start; flex-direction: row; }
.msg .ava-sm { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; background: var(--other); color: #1f2330; display: flex; align-items: center; justify-content: center; font-size: 13px; overflow: hidden; }
.msg .ava-sm img { width: 100%; height: 100%; object-fit: cover; display: block; }
.msg .col { display: flex; flex-direction: column; min-width: 0; max-width: 100%; }
.msg.self .col { align-items: flex-end; }
.msg.other .col { align-items: flex-start; }
.bubble {
  padding: 9px 13px; border-radius: 14px; line-height: 1.55; word-break: break-word;
  background: var(--other); color: var(--text); border: none;
}
.msg.self .bubble { background: var(--self); color: #fff; }
.bubble img { max-width: 220px; max-height: 260px; border-radius: 8px; display: block; cursor: zoom-in; }
.bubble video { max-width: 240px; max-height: 280px; border-radius: 8px; display: block; }
.bubble audio { max-width: 240px; display: block; }
.meta-line { font-size: 11px; color: var(--muted); margin-top: 3px; display: flex; gap: 6px; align-items: center; }
.read-state { color: var(--muted); }
.msg.self .read-state { color: rgba(255,255,255,.72); }
.recall { color: #b98900; cursor: pointer; }
.recall:hover { text-decoration: underline; }
.recalled { font-size: 12px; color: var(--muted); font-style: italic; padding: 4px 0; }

/* 欢迎语气泡（访客端首个提示） */
.welcome-bubble {
  align-self: center; max-width: 88%; text-align: center;
  background: #fff8e8; border: 1px solid #f4e3b0; color: #8a6d1f;
  font-size: 13px; line-height: 1.6; padding: 10px 14px; border-radius: 12px;
}

/* ===================== 设置弹窗 ===================== */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px;
}
.modal-box { width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; background: var(--panel); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-head strong { font-size: 15px; }
.modal-close { border: none; background: none; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.modal-body label { font-size: 13px; color: var(--muted); margin-top: 8px; }
.modal-body input[type=text], .modal-body textarea {
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; font-size: 14px; font-family: inherit; resize: vertical;
}
.ava-edit { display: flex; align-items: center; gap: 12px; }
.ava-prev { width: 52px; height: 52px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 18px; overflow: hidden; flex: 0 0 auto; }
.ava-prev img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ava-edit-r { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.ava-edit-r input[type=file] { font-size: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.chat-input { border-top: 1px solid var(--border); padding: 10px 12px; background: var(--panel); }
.tools { display: flex; gap: 8px; margin-bottom: 8px; }
.tool {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 34px; border: 1px solid var(--border); background: #fff;
  border-radius: 9px; color: var(--text); transition: .15s; padding: 0; cursor: pointer;
}
.tool .tool-icon svg { width: 20px; height: 20px; display: block; }
.tool:hover { border-color: var(--primary); color: var(--primary); }
.tool.recording { background: var(--danger); border-color: var(--danger); color: #fff; }
.send-row { display: flex; gap: 8px; align-items: flex-end; }
.send-row textarea {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; outline: none; max-height: 120px; line-height: 1.5;
}
.send-row textarea:focus { border-color: var(--primary); }
.send-btn { padding: 10px 18px; background: var(--primary); color: #3a2f00; border-radius: 10px; font-weight: 700; transition: background .15s; }
.send-btn:hover { background: var(--primary-dark); }

.blocked-tip { padding: 14px; text-align: center; color: var(--danger); background: #fdeced; font-size: 14px; }

/* ===================== 后台布局 ===================== */
.admin-layout { display: flex; height: 100vh; }
.session-panel {
  width: 320px; flex: 0 0 320px; border-right: 1px solid var(--border);
  background: var(--panel); display: flex; flex-direction: column;
}
.sp-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.sp-head strong { flex: 1; font-size: 15px; }
.sp-search { padding: 10px 12px; }
.sp-search input { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; outline: none; }
.sp-search input:focus { border-color: var(--primary); }
.session-list { flex: 1; overflow-y: auto; list-style: none; }
.session-item { padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s; }
.session-item:hover { background: var(--primary-soft); }
.session-item.active { background: var(--primary-soft); border-left: 3px solid var(--primary); }
.session-item.blocked { opacity: .6; }
.si-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.si-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-unread { background: var(--danger); color: #fff; font-size: 11px; border-radius: 10px; padding: 1px 7px; flex: 0 0 auto; }
.si-sub { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 3px; gap: 8px; }
.si-ip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.si-block { font-size: 11px; color: var(--danger); margin-top: 2px; }
.sp-pager { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); font-size: 13px; }
.sp-pager button { padding: 5px 10px; border: 1px solid var(--border); background: #fff; border-radius: 8px; }
.sp-pager button:disabled { opacity: .4; cursor: not-allowed; }

.chat-panel { flex: 1; display: flex; flex-direction: column; background: var(--panel); min-width: 0; }
.cp-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.cp-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-ops { display: flex; gap: 8px; }
.back-btn { display: none; font-size: 20px; background: none; color: var(--text); padding: 0 6px; }
#adminMessages { flex: 1; }

/* ===================== 手机端自适应 ===================== */
@media (max-width: 760px) {
  .admin-layout { flex-direction: column; }
  .session-panel { width: 100%; flex: 1 1 auto; border-right: none; }
  .chat-panel { display: none; }
  .chat-panel.active {
    display: flex; position: fixed; inset: 0; z-index: 50; background: var(--panel);
  }
  .back-btn { display: inline-block; }

  /* 访客端：隐藏左侧品牌面板，聊天区占满屏 */
  .chat-app { flex-direction: column; width: 100vw; height: 100vh; margin: 0; border-radius: 0; box-shadow: none; }
  .brand-panel { display: none; }
  .msg { max-width: 85%; }
  .bubble img, .bubble video { max-width: 180px; }
}
@media (max-width: 420px) {
  .chat-header { padding: 10px 12px; }
  .tools { gap: 6px; }
  .tool { width: 34px; height: 32px; }
  .tool .tool-icon svg { width: 18px; height: 18px; }
}
