/* =============================================
   Diy客服 — Enterprise Design System v2
   Slate Blue · 专业客服工作台
   ============================================= */

/* -------- Design Tokens -------- */
:root {
  --primary: #3B82F6;
  --primary-hover: #2563EB;
  --primary-light: #EFF6FF;
  --primary-soft: #DBEAFE;
  --sidebar-bg: #0F172A;
  --sidebar-hover: #1E293B;
  --sidebar-active: #1E3A5F;
  --bg: #F1F5F9;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --border-light: #F1F5F9;
  --ink: #0F172A;
  --ink-secondary: #475569;
  --ink-muted: #94A3B8;
  --success: #10B981;
  --success-soft: #ECFDF5;
  --warning: #F59E0B;
  --warning-soft: #FFFBEB;
  --danger: #EF4444;
  --danger-soft: #FEF2F2;
  --online: #10B981;
  --offline: #94A3B8;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.04);
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 6px -1px rgba(15,23,42,.06), 0 2px 4px -2px rgba(15,23,42,.04);
  --shadow-lg: 0 10px 15px -3px rgba(15,23,42,.06), 0 4px 6px -4px rgba(15,23,42,.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  --font-mono: "SF Mono", "Cascadia Code", "Consolas", monospace;
  --transition: 150ms cubic-bezier(.4,0,.2,1);
  --ico-size: 18px;
}

/* -------- Enterprise Icons (inline SVG) -------- */
.ico { width: var(--ico-size); height: var(--ico-size); flex-shrink: 0; display: inline-block; vertical-align: -.2em; }
.ico-sm { width: 14px; height: 14px; }
.ico-lg { width: 22px; height: 22px; }

/* -------- Reset & Base -------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-hover); }

input, textarea, select, button { font-family: inherit; font-size: inherit; }

/* -------- Scrollbar -------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }

/* ======== Buttons ======== */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  color: var(--ink);
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: #F8FAFC; border-color: #CBD5E1; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-secondary); }
.btn-ghost:hover { background: #F1F5F9; color: var(--ink); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #DC2626; border-color: #DC2626; }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-xs { padding: 3px 8px; font-size: 11px; border-radius: 5px; }
.btn-block { width: 100%; }

.btn-icon { padding: 7px; width: 34px; height: 34px; }

/* ======== Badge ======== */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font-size: 10px; font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
  margin-left: auto;
}
.badge-dot {
  min-width: 8px; width: 8px; height: 8px;
  padding: 0; border-radius: 50%;
}
.badge-dot.online { background: #22c55e; }
.badge-dot.offline { background: #cbd5e1; }

/* ======== Status Tags ======== */
.tag {
  display: inline-flex; align-items: center;
  padding: 2px 7px; border-radius: 5px;
  font-size: 10px; font-weight: 600;
  letter-spacing: .3px;
}
.tag-queued { background: #fef3c7; color: #92400e; }
.tag-open { background: #dcfce7; color: #166534; }
.tag-closed { background: #f1f5f9; color: #94a3b8; }
.tag-mine { background: #dbeafe; color: #1d4ed8; }

/* ======== Avatar ======== */
.avatar {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700;
  flex-shrink: 0;
  position: relative;
  letter-spacing: .5px;
}
.avatar-sm { width: 38px; height: 38px; font-size: 15px; }
.avatar .status-dot {
  position: absolute; top: -3px; right: -3px;
  width: 12px; height: 12px;
  border-radius: 50%; border: 2px solid #fff;
  background: #cbd5e1;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
.avatar .status-dot.online { background: #22c55e; }

/* ======== Toast ======== */
.toast-container {
  position: fixed; top: 16px; right: 16px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: toast-in .25s ease-out;
  min-width: 240px; max-width: 360px;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--primary); }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ======== Skeleton ======== */
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
.skeleton {
  background: linear-gradient(90deg, #E2E8F0 25%, #F1F5F9 50%, #E2E8F0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}
.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-text:last-child { width: 60%; margin-bottom: 0; }
.skeleton-avatar { width: 36px; height: 36px; border-radius: 50%; }

/* ======== Keyboard Hint ======== */
.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  border-radius: 4px;
  background: #334155;
  color: #94A3B8;
  font-family: var(--font-mono);
  font-size: 10px; font-weight: 600;
}

/* ============================================ */
/*  PAGE: Home (客户扫码)                        */
/* ============================================ */
.page-home {
  display: flex; align-items: flex-start; justify-content: center;
  min-height: 100vh; padding: 40px 20px 60px;
  background: linear-gradient(160deg, #eff6ff 0%, #f0fdf4 40%, #faf5ff 80%, #f8fafc 100%);
}

.home-wrap { width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 16px; }

/* Header */
.home-hdr { display: flex; align-items: center; gap: 14px; padding: 6px 0; }
.home-hdr-logo {
  width: 48px; height: 48px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--primary) 0%, #1d4ed8 100%);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(59,130,246,.28);
  flex-shrink: 0;
  color: #fff;
}
.home-hdr-logo .ico { width: 24px; height: 24px; }
.home-hdr-info { flex: 1; min-width: 0; }
.home-hdr-name {
  font-size: 1.2rem; font-weight: 700; color: var(--ink);
  line-height: 1.3; display: flex; align-items: center; gap: 8px;
}
.home-hdr-sub { font-size: 13px; color: var(--ink-muted); margin-top: 2px; }
.home-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 20px; line-height: 1.5;
  background: #ecfdf5; color: #047857;
}
.home-badge .ico { width: 14px; height: 14px; }

/* Trust Strip */
.home-trust { display: flex; gap: 10px; }
.home-trust-item {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 8px; text-align: center;
  font-size: 12px; color: var(--ink-secondary); font-weight: 500;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
}
.home-trust-item .ico { width: 18px; height: 18px; color: var(--primary); }

/* Main Card */
.home-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 36px 28px;
  text-align: center;
  overflow: hidden;
}
.home-info, .home-guide { text-align: left; }

/* Steps */
.home-steps { display: flex; justify-content: center; gap: 28px; margin-bottom: 24px; }
.home-step {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--ink-muted); font-weight: 500;
}
.home-step-on { color: var(--primary); font-weight: 600; }
.home-step-done { color: var(--success, #10b981); }
.home-step-num {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  background: var(--bg); color: var(--ink-muted);
  transition: all .2s;
}
.home-step-on .home-step-num { background: var(--primary); color: #fff; }
.home-step-done .home-step-num { background: var(--success, #10b981); color: #fff; }

.home-title { font-size: 1.1rem; font-weight: 700; color: var(--ink); margin-bottom: 8px; }
.home-desc { font-size: 14px; color: var(--ink-secondary); line-height: 1.7; margin-bottom: 24px; }

/* Button */
.home-btn-start {
  padding: 12px 32px; font-size: 15px; font-weight: 600;
  background: linear-gradient(135deg, var(--primary) 0%, #1d4ed8 100%);
  color: #fff; border: none; border-radius: var(--radius);
  cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 4px 14px rgba(59,130,246,.32);
  transition: all .2s;
}
.home-btn-start:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(59,130,246,.4); }
.home-btn-cancel {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 28px; font-size: 14px; font-weight: 500;
  background: var(--bg); color: var(--ink-secondary);
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; margin-top: 16px;
}
.home-btn-again {
  padding: 12px 32px; font-size: 15px; font-weight: 600;
  background: linear-gradient(135deg, var(--primary) 0%, #1d4ed8 100%);
  color: #fff; border: none; border-radius: var(--radius);
  cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 4px 14px rgba(59,130,246,.32);
}

/* QR */
.home-qr-frame {
  width: 210px; height: 210px; margin: 0 auto 16px;
  padding: 8px; background: #fff;
  border: 2px solid var(--border); border-radius: var(--radius);
  position: relative;
}
.home-qr-inner { width: 100%; height: 100%; border-radius: 6px; overflow: hidden; }
.home-qr-inner canvas, .home-qr-inner img { width: 100% !important; height: 100% !important; }
.home-qr-scan {
  position: absolute; left: 12px; right: 12px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--primary), transparent);
  animation: qrScan 2s ease-in-out infinite;
}
@keyframes qrScan {
  0% { top: 12px; opacity: 0; }
  20% { opacity: 1; }
  80% { opacity: 1; }
  100% { top: calc(100% - 16px); opacity: 0; }
}
.home-qr-status { font-size: 13px; color: var(--primary); font-weight: 500; }
.home-countdown {
  font-size: 13px; font-weight: 600;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
  transition: color var(--transition);
}
.home-countdown.is-warning { color: var(--warning); }
.home-countdown.is-danger { color: var(--danger); }
.home-countdown.is-expired { color: var(--danger); font-size: 14px; }

/* Success */
.home-ok-icon {
  width: 64px; height: 64px; margin: 0 auto 16px;
  border-radius: 50%; background: #ecfdf5;
  display: flex; align-items: center; justify-content: center;
  color: #10b981;
}
.home-ok-icon .ico { width: 28px; height: 28px; }
.home-ok-title { font-size: 1.15rem; font-weight: 700; color: #047857; margin-bottom: 8px; }

/* Platform Info */
.home-info-head {
  font-size: 14px; font-weight: 700; color: var(--ink);
  margin-bottom: 16px; display: flex; align-items: center; gap: 6px;
}
.home-info-head .ico { color: var(--primary); }
.home-info-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.home-info-row:last-child { border-bottom: none; padding-bottom: 0; }
.home-info-row .ico { color: var(--ink-muted); width: 16px; height: 16px; margin-top: 1px; flex-shrink: 0; }
.home-info-label { color: var(--ink-secondary); min-width: 54px; }
.home-info-value { color: var(--ink); font-weight: 600; }
.home-info-link { color: var(--primary); text-decoration: none; word-break: break-all; }
.home-info-link:hover { text-decoration: underline; }

/* Guide */
.home-guide-head {
  font-size: 14px; font-weight: 700; color: var(--ink);
  margin-bottom: 12px; display: flex; align-items: center; gap: 6px;
}
.home-guide-head .ico { color: var(--ink-muted); }
.home-guide-img {
  width: 100%; height: auto; border-radius: var(--radius);
  border: 1px solid var(--border); margin-bottom: 12px;
}
.home-guide-steps {
  display: flex; justify-content: center; gap: 12px;
  font-size: 12px; color: var(--ink-muted); font-weight: 500;
}

/* Footer */
.home-footer { text-align: center; font-size: 12px; color: var(--ink-muted); }

/* ============================================ */
/*  PAGE: Login (居中胶囊卡片 v2)                  */
/* ============================================ */
.page-login {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 32px 24px;
  background: #E8F1FB;
  position: relative;
  overflow: hidden;
}

/* ====== Background Blobs ====== */
.login-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.login-blob {
  position: absolute;
  border-radius: 50%;
}
.login-blob-a {
  width: 640px; height: 640px;
  top: -180px; left: -120px;
  background: radial-gradient(circle, rgba(147,197,253,.38), transparent 68%);
}
.login-blob-b {
  width: 800px; height: 800px;
  bottom: -280px; right: -160px;
  background: radial-gradient(circle, rgba(59,130,246,.22), transparent 68%);
}
.login-blob-c {
  width: 420px; height: 420px;
  top: 40%; right: 8%;
  background: radial-gradient(circle, rgba(96,165,250,.15), transparent 70%);
}

/* ====== Card ====== */
.login-card {
  position: relative;
  z-index: 1;
  width: min(460px, calc(100vw - 48px));
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 20px 60px rgba(37,99,235,.10), 0 4px 16px rgba(37,99,235,.04);
  border: 1px solid #E2E8F0;
  padding: 40px 40px 32px;
  animation: loginCardIn .32s ease both;
}
@keyframes loginCardIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ====== Brand ====== */
.login-brand {
  text-align: center;
  margin-bottom: 28px;
}
.login-mark {
  width: 52px; height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #2563EB;
  border-radius: 50%;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 16px;
}
.login-title {
  font-size: 23px;
  font-weight: 700;
  color: #0F172A;
  margin-bottom: 6px;
}
.login-sub {
  font-size: 13px;
  color: #64748B;
}

/* ====== Form ====== */
.login-field {
  margin-bottom: 16px;
}
.login-field-pass {
  position: relative;
}

.login-input {
  width: 100%;
  height: 48px;
  padding: 0 20px;
  border: 1px solid #D8E3F0;
  border-radius: 999px;
  font-size: 14px;
  color: #0F172A;
  background: #F8FAFC;
  outline: none;
  font-family: var(--font);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.login-input::placeholder {
  color: #94A3B8;
}
.login-input:focus {
  border-color: #3B82F6;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

/* Password field: right padding for eye icon */
.login-field-pass .login-input {
  padding-right: 44px;
}

/* Error state */
.login-field.is-error .login-input {
  border-color: #F87171;
}
.login-field.is-error .login-input:focus {
  box-shadow: 0 0 0 3px rgba(248,113,113,.15);
}

/* Eye toggle */
.login-eye {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  border-radius: 50%;
  line-height: 0;
  transition: opacity var(--transition);
}
.login-eye:hover {
  opacity: .7;
}

/* Error text */
.login-error {
  color: #B91C1C;
  font-size: 13px;
  margin-bottom: 4px;
  text-align: left;
  padding-left: 20px;
}

/* Submit */
.login-submit {
  display: block;
  width: 100%;
  height: 48px;
  margin-top: 8px;
  border: none;
  border-radius: 999px;
  background: #3B82F6;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: .04em;
  font-family: var(--font);
  transition: background var(--transition), opacity var(--transition);
}
.login-submit:hover {
  background: #2563EB;
}
.login-submit:disabled {
  opacity: .55;
  cursor: not-allowed;
}

/* Tip */
.login-tip {
  text-align: center;
  font-size: 12px;
  color: #94A3B8;
  margin-top: 22px;
}

/* Copyright outside card */
.login-copy {
  position: relative;
  z-index: 1;
  margin-top: 24px;
  font-size: 12px;
  color: #94A3B8;
  text-align: center;
}

/* ====== Responsive ====== */
@media (max-width: 480px) {
  .page-login {
    padding: 20px 16px;
  }
  .login-card {
    padding: 28px 22px 24px;
  }
  .login-blob-a {
    width: 400px; height: 400px;
    top: -120px; left: -80px;
  }
  .login-blob-b {
    width: 500px; height: 500px;
    bottom: -160px; right: -100px;
  }
  .login-blob-c {
    display: none;
  }
  .login-title {
    font-size: 20px;
  }
}

/* ============================================ */
/*  PAGE: Desk (客服工作台)                       */
/* ============================================ */
.page-desk {
  display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
  background: #f0f2f5;
}

/* Top Bar */
.desk-top {
  display: flex; align-items: center;
  height: 52px; padding: 0 20px;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  gap: 16px;
  z-index: 10;
  flex-shrink: 0;
}
.desk-brand {
  font-weight: 700; font-size: 15px;
  color: #1e293b; white-space: nowrap;
  display: flex; align-items: center; gap: 8px;
}
.desk-brand .dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; }

.desk-search {
  flex: 1; max-width: 360px; position: relative;
}
.desk-search input {
  width: 100%; height: 34px;
  padding: 0 12px 0 34px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 13px;
  background: #f8fafc;
  color: var(--ink);
  outline: none;
  transition: all .15s;
}
.desk-search input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
  background: var(--surface);
}
.desk-search input::placeholder { color: var(--ink-muted); }
.desk-search .search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--ink-muted); pointer-events: none;
  display: flex; align-items: center; justify-content: center;
}
.desk-search .search-icon svg {
  color: inherit;
}

.desk-stats {
  flex: 1; text-align: center;
  font-size: 12px; color: #64748b;
  display: flex; align-items: center; justify-content: center; gap: 16px;
}
.desk-stats .stat-item { display: flex; align-items: center; gap: 4px; }
.desk-stats .stat-num { font-weight: 700; font-size: 15px; color: #1e293b; }

.desk-user {
  display: flex; align-items: center; gap: 12px;
  font-size: 13px; white-space: nowrap;
}

.online-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff; cursor: pointer;
  font-size: 12px; font-weight: 600; color: var(--ink-secondary);
  transition: all var(--transition);
}
.online-toggle-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #cbd5e1; flex-shrink: 0;
}
.online-toggle.is-on {
  border-color: rgba(16,185,129,.35);
  background: #ecfdf5; color: #047857;
}
.online-toggle.is-on .online-toggle-dot {
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16,185,129,.18);
}
.online-toggle.is-off {
  border-color: var(--border);
  background: #f8fafc; color: #64748b;
}
.online-toggle:hover { filter: brightness(0.98); }

.desk-filters .filter-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  margin-left: 4px; border-radius: 999px;
  background: #ef4444; color: #fff;
  font-size: 11px; font-weight: 700; line-height: 1;
}
.desk-filters .filter-badge.hidden { display: none; }
.desk-user-info {
  display: flex; align-items: center; gap: 8px;
}
.desk-user .user-avatar {
  width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.desk-user .user-name { color: var(--ink); font-weight: 500; }

/* Desk nav dropdown */
.desk-nav { position: relative; }
.desk-nav-current {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--ink);
  cursor: pointer; padding: 6px 10px; border-radius: var(--radius);
  transition: background var(--transition);
  user-select: none;
}
.desk-nav-current:hover { background: var(--bg); }
.desk-nav-current::after {
  content: '▾'; font-size: 10px; margin-left: 2px; opacity: .4;
}
.desk-nav-menu {
  position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 180px; padding: 6px;
  z-index: 60;
  animation: nav-fade-in .15s ease-out;
}
@keyframes nav-fade-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.desk-nav-menu.hidden { display: none; }
.desk-nav-menu a {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 6px;
  font-size: 13px; font-weight: 500;
  color: var(--ink-secondary); text-decoration: none;
  transition: all var(--transition);
}
.desk-nav-menu a:hover { background: var(--primary-light); color: var(--primary); }
.desk-nav-menu a.is-current { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.desk-nav-menu hr { border: none; border-top: 1px solid var(--border-light); margin: 4px 8px; }

/* Body: Sidebar + Chat */
.desk-body {
  flex: 1; display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 0; overflow: hidden;
}

/* Chat Wrapper: chat + canned sidebar (flex row) */
.desk-chat-wrapper {
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* Sidebar */
.desk-list {
  display: flex; flex-direction: column;
  background: #f8fafc;
  border-right: 1px solid #e2e8f0;
  min-height: 0; overflow: hidden;
}
.desk-filters {
  display: flex; gap: 4px;
  padding: 12px;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0; background: #fff;
}
.desk-filters button {
  flex: 1;
  border: 0; background: #f1f5f9;
  padding: 6px 0; border-radius: 8px;
  cursor: pointer;
  color: #64748b;
  font-size: 12px; font-weight: 500;
  transition: all .15s;
  text-align: center;
}
.desk-filters button:hover { color: #334155; background: #e2e8f0; }
.desk-filters button.is-active {
  background: #3b82f6;
  color: #fff;
  box-shadow: 0 1px 3px rgba(59,130,246,.3);
}

.conv-list {
  list-style: none; margin: 0; padding: 6px 8px;
  overflow-y: auto; flex: 1;
}
.conv-list li {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px;
  cursor: pointer;
  border-radius: 10px;
  margin-bottom: 2px;
  border: none;
  transition: background .12s, box-shadow .12s, opacity .12s;
  border-left: none;
}
.conv-list li:hover { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.conv-list li.is-active {
  background: #eff6ff;
  box-shadow: inset 2px 0 0 #3b82f6;
}
/* Pinned & Muted states */
.conv-list li.is-pinned {
  background: #fffbeb;
}
.conv-list li.is-pinned:hover {
  background: #fef3c7;
}
.conv-list li.is-muted {
  opacity: .48;
}
.conv-list li.is-muted:hover {
  opacity: .7;
}
.pin-dot, .mute-dot {
  font-size: 11px; flex-shrink: 0; line-height: 1;
}
.pin-dot { filter: grayscale(0); }
.mute-dot { opacity: .6; }
.conv-list li .conv-info { flex: 1; min-width: 0; }
.conv-list li .conv-name {
  display: flex; align-items: center; gap: 4px;
  font-weight: 600; font-size: 13.5px; color: #1e293b;
  margin-bottom: 4px;
}
.conv-list li .conv-name span:first-of-type {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-list li .conv-preview {
  font-size: 12px; color: #94a3b8;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 4px;
}
.conv-list li .conv-meta {
  display: flex; align-items: center; gap: 6px;
}
.agent-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}
.conv-list li .conv-time {
  font-size: 11px; color: #94a3b8; white-space: nowrap;
}
.conv-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 20px; color: #94a3b8; font-size: 13px; text-align: center;
  gap: 10px;
}

/* Chat Area */
.desk-chat {
  display: flex; flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0; overflow: hidden;
  background: var(--bg);
}
.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  font-weight: 600; font-size: 14px;
  flex-shrink: 0;
}
.chat-head .chat-head-left { display: flex; align-items: center; gap: 8px; }
.chat-head .btn-back { display: none; }
#chatHeadTitle { display: flex; align-items: center; gap: 8px; }

.btn-menu-toggle { display: none !important; }
.btn-menu-toggle .ico { margin-right: 0; }

.chat-actions {
  padding: 8px 20px;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  display: flex; gap: 6px;
  flex-shrink: 0;
}

/* Messages */
.chat-msgs {
  flex: 1; overflow-y: auto;
  padding: 16px 20px;
  display: flex; flex-direction: column; gap: 10px;
  background: #f0f2f5;
}
.chat-msgs-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--ink-muted); font-size: 14px;
}

/* Time separator (WeChat-style centered time stamps) */
.chat-time-sep {
  text-align: center;
  padding: 8px 0 6px;
  font-size: 12px;
  color: var(--ink-muted);
  user-select: none;
}

.bubble {
  max-width: 74%;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  line-height: 1.55;
  font-size: 14px;
  word-break: break-word;
  position: relative;
}
.bubble-in {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.bubble-out {
  align-self: flex-end;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 1px 3px rgba(59,130,246,.25);
}
.bubble-system {
  align-self: center;
  background: #F1F5F9;
  color: var(--ink-muted);
  font-size: 12px;
  max-width: 85%;
  text-align: center;
  border-radius: var(--radius);
  padding: 6px 14px;
}

.bubble-img {
  display: block;
  max-width: 240px;
  max-height: 320px;
  border-radius: var(--radius);
  object-fit: cover;
  cursor: pointer;
}
.bubble-img + .bubble-meta { display: block; margin-top: 4px; }

/* Image lightbox */
.img-lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.img-lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
  object-fit: contain;
}
.img-lightbox-close {
  position: absolute; top: 16px; right: 16px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  color: #fff;
  border: none;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .2s;
}
.img-lightbox-close:hover { background: rgba(255,255,255,.3); }
.img-lightbox-close .ico { width: 18px; height: 18px; }

.bubble-meta {
  display: block; margin-top: 4px;
  font-size: 11px; opacity: .65;
}
.bubble-in .bubble-meta { color: var(--ink-muted); }
.bubble-out .bubble-meta { color: rgba(255,255,255,.8); }

.bubble .sender-label {
  font-size: 11px; font-weight: 600; margin-bottom: 2px;
  color: var(--primary);
}

/* Canned Bar */
.chat-canned {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 8px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  max-height: 80px; overflow-y: auto;
}
.chat-canned button {
  border: 1px solid var(--border);
  background: #F8FAFC;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--ink-secondary);
  transition: all var(--transition);
  white-space: nowrap;
}
.chat-canned button:hover {
  background: var(--primary-light);
  border-color: var(--primary-soft);
  color: var(--primary);
}

/* Compose */
.chat-compose {
  padding: 12px 20px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.compose-preview {
  position: relative;
  display: inline-block;
  margin-bottom: 10px;
}
.compose-preview.hidden { display: none; }
.compose-preview img {
  max-width: 140px;
  max-height: 140px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  object-fit: cover;
  display: block;
}
.compose-preview-remove {
  position: absolute;
  top: -6px; right: -6px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: 2px solid var(--surface);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  padding: 0;
  font-size: 10px;
  line-height: 1;
  box-shadow: var(--shadow-sm);
}
.compose-preview-remove:hover { background: #dc2626; }
.compose-preview-remove .ico { width: 10px; height: 10px; }

.compose-row {
  display: flex; align-items: flex-end; gap: 8px;
}
.compose-row textarea {
  flex: 1; resize: none; min-width: 0;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  background: #fff;
}
.compose-row textarea:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}
.compose-row textarea::placeholder { color: var(--ink-muted); }

.compose-image-btn {
  color: var(--ink-muted);
  padding: 6px 10px;
  flex-shrink: 0;
}
.compose-image-btn:hover { color: var(--primary); }

.chat-compose .btn-primary {
  flex-shrink: 0;
}

/* Canned Toggle Button (in chat head) */
.canned-toggle { margin-left: auto; }
.canned-toggle.is-active { background: var(--primary-light); color: var(--primary); border-color: var(--primary-soft); }

/* Canned Reply Sidebar */
.canned-sidebar {
  display: flex; flex-direction: column;
  width: 260px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
}
.canned-sidebar.hidden { display: none; }
.canned-sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 13px;
  flex-shrink: 0;
}
.canned-sidebar-search { padding: 8px 12px; border-bottom: 1px solid var(--border-light); flex-shrink: 0; }
.canned-sidebar-search input {
  width: 100%; height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
  transition: border-color var(--transition);
}
.canned-sidebar-search input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
  background: var(--surface);
}
.canned-sidebar-list {
  flex: 1; overflow-y: auto;
  padding: 8px;
}
.canned-sidebar-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  margin-bottom: 4px;
}
.canned-sidebar-item:hover {
  background: var(--primary-light);
  border-color: var(--primary-soft);
}
.canned-sidebar-item:active { transform: scale(.98); }
.canned-sidebar-item .canned-item-title {
  font-size: 13px; font-weight: 600;
  color: var(--ink);
  margin-bottom: 3px;
}
.canned-sidebar-item .canned-item-preview {
  font-size: 12px; color: var(--ink-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.canned-sidebar-empty {
  text-align: center; padding: 32px 16px;
  color: var(--ink-muted); font-size: 13px;
}
.canned-sidebar-empty a { text-decoration: underline; }

/* Inline Add Form inside Canned Sidebar */
.canned-add-toggle { margin-right: 0; font-size: 12px; }
.canned-sidebar-add {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.canned-sidebar-add.hidden { display: none; }
.canned-add-input,
.canned-add-textarea {
  width: 100%;
  padding: 7px 9px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
  font-family: inherit;
  transition: border-color var(--transition);
  box-sizing: border-box;
}
.canned-add-textarea { resize: vertical; min-height: 56px; }
.canned-add-input:focus,
.canned-add-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
  background: var(--surface);
}
.canned-add-actions {
  display: flex; gap: 6px;
  margin-bottom: 4px;
}
.canned-add-msg {
  font-size: 12px;
  margin-top: 4px;
}
.canned-add-msg.hidden { display: none; }

/* Keyboard Hint Bar */
.keyboard-hints {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  padding: 5px 20px;
  background: var(--sidebar-bg);
  border-top: 1px solid #1E293B;
  flex-shrink: 0;
}
.keyboard-hints .hint {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: #64748B;
}

/* ============================================ */
/*  PAGE: Settings / Canned                      */
/* ============================================ */
.page-settings {
  min-height: 100vh;
  background: var(--bg);
}
.settings-wrap {
  max-width: 680px; margin: 0 auto;
  padding: 32px 20px 60px;
}
.settings-head {
  margin-bottom: 24px;
}
.settings-head a {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; color: var(--ink-muted);
  margin-bottom: 12px;
}
.settings-head a:hover { color: var(--primary); }
.settings-head h1 {
  font-size: 1.35rem; font-weight: 700;
  color: var(--ink);
}

.settings-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}
.settings-form label {
  display: block;
  margin-bottom: 18px;
  font-size: 12px; font-weight: 500;
  color: var(--ink-secondary);
  text-transform: uppercase; letter-spacing: .03em;
}
.settings-form input,
.settings-form textarea,
.settings-form select {
  display: block; width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.settings-form textarea { resize: vertical; min-height: 80px; }
.settings-form input:focus,
.settings-form textarea:focus,
.settings-form select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}
.settings-form .btn { margin-top: 4px; }

.canned-manage {
  list-style: none; padding: 0;
  margin-top: 24px;
}
.canned-manage li {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  margin-bottom: 8px;
  transition: box-shadow var(--transition);
}
.canned-manage li:hover { box-shadow: var(--shadow-sm); }
.canned-manage li .canned-body { flex: 1; min-width: 0; }
.canned-manage li strong { font-size: 14px; display: block; margin-bottom: 4px; }
.canned-manage li p { font-size: 13px; color: var(--ink-secondary); white-space: pre-wrap; word-break: break-all; }

.form-error {
  color: var(--danger); font-size: 12px;
  margin-bottom: 12px;
}

/* ============================================ */
/*  Utility Classes                              */
/* ============================================ */
.muted { color: var(--ink-muted); }
.text-sm { font-size: 12px; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.hidden { display: none !important; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-2 { margin-bottom: 8px; }

/* ============================================ */
/*  Responsive                                   */
/* ============================================ */
@media (max-width: 860px) {
  /* ---- Top bar collapse ---- */
  .desk-top {
    height: 48px; padding: 0 12px; gap: 8px;
  }
  .desk-brand { font-size: 14px; }
  .desk-search { max-width: 140px; }
  .desk-search input { height: 30px; font-size: 12px; padding-left: 28px; }
  .desk-stats { display: none; }
  .desk-user { gap: 6px; font-size: 12px; }
  .desk-nav-menu { display: none; }
  .desk-nav-menu.hidden { display: none; }
  .desk-nav-menu:not(.hidden) {
    display: flex; flex-direction: column;
    position: fixed; top: 48px; right: 8px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
    padding: 8px; z-index: 50; min-width: 160px;
  }
  .desk-nav-current { font-size: 12px; padding: 4px 8px; }
  .desk-user-info .user-name { display: none; }
  .btn-menu-toggle { display: inline-flex !important; }

  /* ---- Body: single column ---- */
  .desk-body { grid-template-columns: 1fr; position: relative; }

  /* List: full screen by default, hidden when chat active */
  .desk-list {
    position: absolute; inset: 0; z-index: 5;
    max-height: none; border-right: 0;
    transition: transform .25s ease;
  }
  .desk-list.is-hidden { transform: translateX(-100%); }

  /* Chat wrapper: full screen */
  .desk-chat-wrapper {
    position: absolute; inset: 0; z-index: 6;
    flex-direction: column;
    transition: transform .25s ease;
  }
  .desk-chat-wrapper.is-list { transform: translateX(100%); }

  /* Chat head: add back button */
  .chat-head { padding: 8px 12px; gap: 8px; }
  .chat-head .btn-back { display: inline-flex !important; }

  /* Chat messages: fill space */
  .chat-msgs { padding: 12px; }

  /* Compose: compact */
  .chat-compose { padding: 8px 10px 10px; }
  .compose-row textarea { font-size: 14px; padding: 8px 10px; min-height: 40px; }
  .compose-row .btn { font-size: 13px; padding: 8px 12px; }
  .compose-preview img { max-width: 100px; max-height: 100px; }

  /* Bubbles */
  .bubble { max-width: 88%; }
  .bubble-img { max-width: 180px; max-height: 240px; }

  /* Canned sidebar overlay */
  .canned-sidebar {
    position: fixed; top: 48px; right: 0; bottom: 0; left: 0;
    z-index: 30; width: auto !important;
    border-radius: 0; border: none;
    box-shadow: none;
  }
  .canned-sidebar.hidden { display: none; }
  .canned-sidebar-head { padding: 12px; }
  .canned-sidebar-item { padding: 14px 12px; }

  /* Conversation list items: bigger touch targets */
  .conv-item { padding: 14px 12px; }
  .conv-avatar { width: 40px; height: 40px; font-size: 16px; }

  /* Filters scrolling */
  .desk-filters { padding: 8px 10px; gap: 6px; overflow-x: auto; }
  .desk-filters button { font-size: 12px; padding: 6px 12px; white-space: nowrap; }

  /* Keyboard hints hidden */
  .keyboard-hints { display: none; }

  /* Settings page */
  .page-settings .card { padding: 20px; }
}

/* Customer Remark */
.conv-wxid { display: block; font-size: 11px; font-weight: 400; color: var(--ink-muted); margin-top: 1px; }
.customer-remark { display: none; font-size: 12px; color: var(--ink-secondary); margin-left: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.customer-remark .btn-link { font-size: 11px; padding: 0; background: none; border: none; color: var(--primary); cursor: pointer; text-decoration: none; }
.customer-remark .btn-link:hover { text-decoration: underline; }
.customer-remark .remark-text { color: var(--ink); }
.remark-input { width: 120px; height: 24px; padding: 0 6px; border: 1px solid var(--primary); border-radius: 4px; font-size: 12px; outline: none; }
.remark-input:focus { box-shadow: 0 0 0 2px rgba(59,130,246,.15); }

/* ═══════ Right-Click Context Menu ═══════ */
.context-menu {
  position: fixed; z-index: 9999; min-width: 170px;
  background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.06);
  padding: 4px;
  opacity: 0; transform: scale(.92);
  transition: opacity .12s, transform .12s;
  pointer-events: none;
}
.context-menu.open {
  opacity: 1; transform: scale(1); pointer-events: auto;
}
.context-menu .menu-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 6px; font-size: 13px;
  color: #334155; cursor: pointer; transition: background .1s;
  user-select: none;
}
.context-menu .menu-item:hover { background: #f1f5f9; }
.context-menu .menu-item.danger { color: #ef4444; }
.context-menu .menu-item.danger:hover { background: #fef2f2; }
.context-menu .menu-divider {
  height: 1px; background: #e2e8f0; margin: 4px 8px;
}
.context-menu .menu-icon {
  width: 18px; text-align: center; flex-shrink: 0; font-size: 13px;
}

/* 仅专属链接开关 */
.switch-sm {
  position: relative; display: inline-block; width: 36px; height: 20px;
  vertical-align: middle;
}
.switch-sm input { opacity: 0; width: 0; height: 0; }
.switch-sm span {
  position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
  background: #cbd5e1; border-radius: 20px; transition: .2s;
}
.switch-sm span:before {
  content: ''; position: absolute; height: 14px; width: 14px;
  left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .2s;
}
.switch-sm input:checked + span { background: #8b5cf6; }
.switch-sm input:checked + span:before { transform: translateX(16px); }
