:root {
  --brand: #ee4d2d;
  --brand-dark: #d73211;
  --brand-soft: #fff1ec;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e8eaed;
  --line-strong: #d9dde3;
  --text: #17191c;
  --muted: #727a86;
  --muted-2: #9aa1ab;
  --success: #16794a;
  --success-soft: #e8f7ef;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
body.chat-page {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: #f7f8f9; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.ghost { background: #fff; }
.btn.text { border-color: transparent; background: transparent; color: var(--muted); }
.btn.text:hover { color: var(--text); background: #f2f3f5; }
.btn.small { height: 30px; padding: 0 10px; font-size: 12px; }
.btn.icon { width: 32px; height: 32px; padding: 0; font-size: 20px; line-height: 1; }
.mobile-only { display: none; }

.input,
.select {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus,
.select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(238, 77, 45, 0.12);
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: #f0f1f3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.pill.brand { background: var(--brand-soft); color: var(--brand-dark); }

/* ---------- 登录页 ---------- */
.auth-page {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 480px at 12% -10%, rgba(238, 77, 45, 0.16), transparent 60%),
    radial-gradient(720px 420px at 100% 110%, rgba(23, 25, 28, 0.08), transparent 55%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 392px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 34px 32px 28px;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 26px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(140deg, #ff7a4d, var(--brand));
  color: #fff;
  font-weight: 800;
  font-size: 18px;
}
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card p.sub { margin: 0 0 24px; color: var(--muted); font-size: 13px; }
.field { margin-bottom: 16px; }
.field label {
  display: block;
  margin-bottom: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.field .input { width: 100%; height: 42px; }
.auth-submit { width: 100%; height: 42px; margin-top: 6px; }
.auth-error {
  display: none;
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.5;
}
.auth-error.show { display: block; }
.auth-foot { margin-top: 18px; color: var(--muted-2); font-size: 12px; text-align: center; }

/* ---------- 顶部栏 ---------- */
.topbar {
  height: 60px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; }
.brand .brand-mark { width: 30px; height: 30px; border-radius: 9px; font-size: 16px; }
.topbar .select { min-width: 170px; }
.topbar .search { flex: 1; max-width: 360px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.user-name { font-size: 13px; color: var(--muted); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 主布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: 352px minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.conv-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px;
}
.panel-head h2 { margin: 0; font-size: 14px; }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 14px; }
.conv-item {
  width: 100%;
  display: flex;
  gap: 11px;
  padding: 11px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  transition: background 0.12s ease;
}
.conv-item:hover { background: #f7f8f9; }
.conv-item.active { background: var(--brand-soft); }
.conv-item.active .conv-name { color: var(--brand-dark); }
.conv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.conv-row { display: flex; align-items: center; gap: 8px; }
.conv-name {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-time { font-size: 11px; color: var(--muted-2); white-space: nowrap; }
.conv-preview {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-shop {
  font-size: 11px;
  color: var(--muted-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.unread-badge {
  min-width: 19px;
  height: 19px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.avatar {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  background: hsl(var(--hue, 14) 72% 52%);
  text-transform: uppercase;
}
.avatar.small { width: 30px; height: 30px; font-size: 12px; }
.conv-item .avatar { width: 40px; height: 40px; }

/* ---------- 聊天区 ---------- */
.chat-panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #fbfbfc; }
.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  line-height: 1.7;
  padding: 24px;
}
.empty.small { font-size: 13px; padding: 32px 18px; }
.empty .empty-title { font-size: 16px; font-weight: 600; color: var(--text); }
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head {
  display: flex;
  align-items: center;
  gap: 11px;
  height: 64px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.chat-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chat-title strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title span { font-size: 12px; }
.chat-head .btn { margin-left: auto; }
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg { display: flex; gap: 9px; max-width: min(720px, 82%); }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; flex-direction: row-reverse; }
.msg-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.msg-meta { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--muted-2); }
.msg.out .msg-meta { justify-content: flex-end; }
.bubble {
  padding: 9px 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 13.5px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.out .bubble { background: var(--brand-soft); border-color: #ffd7cb; }
.bubble.media { padding: 6px; }
.bubble img { display: block; max-width: 260px; max-height: 260px; border-radius: 8px; }
.bubble .file-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: #f3f4f6;
  font-size: 12px;
  color: var(--muted);
}
.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 18px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1;
  min-height: 42px;
  max-height: 132px;
  resize: none;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  font-size: 13.5px;
  line-height: 1.5;
  outline: none;
}
.composer textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(238, 77, 45, 0.1); }
.composer .btn { height: 42px; padding: 0 20px; }

/* ---------- 店铺页 ---------- */
.page-wrap { max-width: 1120px; margin: 0 auto; padding: 26px 20px 60px; }
.page-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-title h1 { margin: 0 0 4px; font-size: 22px; }
.page-title p { margin: 0; color: var(--muted); font-size: 13px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.banner {
  display: none;
  margin-bottom: 16px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.banner.show { display: block; }
.banner.ok { background: var(--success-soft); color: var(--success); }
.banner.err { background: var(--danger-soft); color: var(--danger); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 13px 16px; text-align: left; border-bottom: 1px solid var(--line); }
.table th { background: #fafbfc; color: var(--muted); font-size: 12px; font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table .actions { display: flex; gap: 8px; justify-content: flex-end; }
.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--success-soft);
  color: var(--success);
}
.tag.expired { background: var(--danger-soft); color: var(--danger); }
.tag.revoked { background: #f0f1f3; color: var(--muted); }
.table-empty { padding: 46px 20px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.8; }

/* ---------- 系统设置 ---------- */
.settings-card { padding: 24px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 18px;
}
.form-grid .field.full { grid-column: 1 / -1; }
.field .select { width: 100%; height: 42px; }
.copy-row { display: flex; gap: 8px; }
.copy-row .input {
  flex: 1;
  min-width: 0;
  background: #fafbfc;
  color: var(--muted);
  font-size: 12.5px;
}
.copy-row .btn { height: 42px; flex: 0 0 auto; }
.settings-hint {
  margin: 2px 0 18px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  background: #f7f8f9;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.8;
}
.settings-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.settings-actions .btn { height: 40px; }
.settings-note {
  margin-top: 16px;
  padding: 18px 20px;
  font-size: 13px;
  line-height: 1.9;
  color: var(--muted);
}
.settings-note strong { color: var(--text); }
.settings-note ol { margin: 8px 0 0; padding-left: 20px; }
.settings-note code {
  padding: 2px 6px;
  border-radius: 5px;
  background: #f2f3f5;
  color: var(--text);
  font-size: 12px;
}
.tag.off { background: var(--danger-soft); color: var(--danger); }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(12px);
  max-width: min(520px, calc(100vw - 40px));
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(23, 25, 28, 0.92);
  color: #fff;
  font-size: 13px;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: rgba(192, 57, 43, 0.95); }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 12px; gap: 8px; }
  .topbar .search { order: 5; flex-basis: 100%; max-width: none; }
  .top-actions .user-name { display: none; }
  .layout { grid-template-columns: 1fr; }
  .chat-panel { display: none; }
  body.chat-open .conv-panel { display: none; }
  body.chat-open .chat-panel { display: flex; }
  .mobile-only { display: inline-flex; }
  .messages { padding: 14px 12px 6px; }
  .msg { max-width: 92%; }
  .composer { padding: 10px 12px 12px; }
  .table th:nth-child(4), .table td:nth-child(4),
  .table th:nth-child(5), .table td:nth-child(5) { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .settings-card { padding: 18px; }
}
