/* =============================================
   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: 20px; height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px; font-weight: 600;
  line-height: 1;
}
.badge-dot {
  min-width: 8px; width: 8px; height: 8px;
  padding: 0; border-radius: 50%;
}
.badge-dot.online { background: var(--online); }
.badge-dot.offline { background: var(--offline); }

/* ======== Status Tags ======== */
.tag {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 500;
}
.tag-queued { background: var(--warning-soft); color: #B45309; }
.tag-open { background: var(--success-soft); color: #047857; }
.tag-closed { background: #F1F5F9; color: var(--ink-muted); }
.tag-mine { background: var(--primary-light); color: var(--primary-hover); }

/* ======== Avatar ======== */
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-hover);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600;
  flex-shrink: 0;
  position: relative;
}
.avatar-sm { width: 28px; height: 28px; font-size: 12px; }
.avatar .status-dot {
  position: absolute; bottom: -1px; right: -1px;
  width: 10px; height: 10px;
  border-radius: 50%; border: 2px solid #fff;
  background: var(--offline);
}
.avatar .status-dot.online { background: var(--online); }

/* ======== 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: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(59,130,246,.06), transparent 60%),
    radial-gradient(ellipse 60% 40% at 90% 100%, rgba(16,185,129,.04), transparent 50%),
    var(--bg);
}

.home-wrap { width: 100%; max-width: 440px; }

.home-brand { text-align: center; margin-bottom: 28px; }
.home-brand h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; color: var(--ink); margin-bottom: 6px; }
.home-brand p { color: var(--ink-secondary); font-size: 14px; }

.home-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  text-align: center;
}
.home-lead { color: var(--ink-secondary); line-height: 1.7; margin-bottom: 20px; }
.home-lead:last-child { margin-bottom: 0; }

.qr-box {
  width: 220px; height: 220px;
  margin: 20px auto;
  display: flex; align-items: center; justify-content: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.home-status { font-size: 13px; color: var(--primary); font-weight: 500; margin-top: 12px; }
.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; }
.home-ok-title { font-size: 1.25rem; font-weight: 700; margin-bottom: 8px; color: var(--success); }

.home-panel .btn { margin-top: 8px; }

/* 操作指引 + 备案提示 */
.home-guide {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-top: 24px;
  text-align: center;
}
.home-guide h2 {
  font-size: 15px; font-weight: 700;
  color: var(--ink);
  margin-bottom: 10px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.home-guide p {
  font-size: 13px; color: var(--ink-secondary); margin-bottom: 14px;
  line-height: 1.6;
}
.home-guide-img {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 14px;
  display: block;
}
.home-guide-notice {
  font-size: 14px; font-weight: 700;
  color: var(--danger) !important;
  line-height: 1.6;
  display: flex; align-items: flex-start; justify-content: center; gap: 6px;
}
.home-guide-notice .ico {
  flex-shrink: 0;
  margin-top: 1px;
  vertical-align: middle;
}

/* ============================================ */
/*  PAGE: Login (客服登录)                        */
/* ============================================ */
.page-login {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(59,130,246,.06), transparent 60%),
    var(--bg);
}

.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}
.login-card h1 {
  font-size: 1.35rem; font-weight: 700;
  margin-bottom: 4px; color: var(--ink);
}
.login-card .muted { color: var(--ink-secondary); font-size: 13px; margin-bottom: 24px; }

.login-card label {
  display: block;
  margin-bottom: 16px;
  font-size: 12px; font-weight: 500;
  color: var(--ink-secondary);
  text-transform: uppercase; letter-spacing: .03em;
}
.login-card input {
  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);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.login-card input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
.login-card .btn { margin-top: 8px; }

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

@media (max-width: 480px) {
  .login-card {
    padding: 24px 20px;
    border-radius: var(--radius);
  }
  .login-card h1 { font-size: 1.2rem; }
}

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

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

.desk-search {
  flex: 1; max-width: 360px; position: relative;
}
.desk-search input {
  width: 100%; height: 34px;
  padding: 0 12px 0 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
  transition: all var(--transition);
}
.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: var(--ink-secondary);
  display: flex; align-items: center; justify-content: center; gap: 12px;
}
.desk-stats .stat-item { display: flex; align-items: center; gap: 4px; }
.desk-stats .stat-num { font-weight: 700; font-size: 14px; color: var(--ink); }

.desk-user {
  display: flex; align-items: center; gap: 12px;
  font-size: 13px; white-space: nowrap;
}
.desk-user-info {
  display: flex; align-items: center; gap: 8px;
}
.desk-user .user-avatar {
  width: 28px; height: 28px; border-radius: 7px;
  background: linear-gradient(135deg, var(--primary), #1d4ed8);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; 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: var(--surface);
  border-right: 1px solid var(--border);
  min-height: 0; overflow: hidden;
}
.desk-filters {
  display: flex; gap: 4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.desk-filters button {
  flex: 1;
  border: 0; background: transparent;
  padding: 6px 0; border-radius: 6px;
  cursor: pointer;
  color: var(--ink-muted);
  font-size: 12px; font-weight: 500;
  transition: all var(--transition);
  text-align: center;
}
.desk-filters button:hover { color: var(--ink); background: var(--bg); }
.desk-filters button.is-active {
  background: var(--primary);
  color: #fff;
}

.conv-list {
  list-style: none; margin: 0; padding: 0;
  overflow-y: auto; flex: 1;
}
.conv-list li {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition);
}
.conv-list li:hover { background: #F8FAFC; }
.conv-list li.is-active {
  background: var(--primary-light);
  border-left: 3px solid var(--primary);
  padding-left: 11px;
}
.conv-list li .conv-info { flex: 1; min-width: 0; }
.conv-list li .conv-name {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-weight: 600; font-size: 13px;
  margin-bottom: 3px;
}
.conv-list li .conv-preview {
  font-size: 12px; color: var(--ink-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-list li .conv-meta {
  display: flex; align-items: center; gap: 6px;
  margin-top: 4px;
}
.conv-list li .conv-time {
  font-size: 11px; color: var(--ink-muted); white-space: nowrap;
}
.conv-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 20px; color: var(--ink-muted); font-size: 13px; text-align: center;
  gap: 8px;
}

/* 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: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  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: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; gap: 6px;
  flex-shrink: 0;
}

/* Messages */
.chat-msgs {
  flex: 1; overflow-y: auto;
  padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
  background:
    repeating-linear-gradient(
      0deg, transparent, transparent 3px,
      rgba(148,163,184,.03) 3px, rgba(148,163,184,.03) 6px
    );
}
.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: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}
.bubble-out {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.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 var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.compose-row textarea:focus {
  border-color: var(--primary);
  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); }
