/* ClawBot - WeChat-style dark UI */
:root {
  --bg: #1a1a1a;
  --bg-card: #2a2a2a;
  --bg-input: #333;
  --border: #333;
  --text: #fff;
  --text-sub: #999;
  --primary: #07c160;
  --bubble-out: #95ec69;
  --bubble-in: #2a2a2a;
}
body.light-mode {
  --bg: #f5f5f5;
  --bg-card: #fff;
  --bg-input: #f0f0f0;
  --border: #e0e0e0;
  --text: #333;
  --text-sub: #666;
  --bubble-in: #fff;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
html, body { height: 100vh; background: var(--bg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
}
#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  position: relative;
  display: flex;
  flex-direction: column;
}

#page-chat {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

/* ---- login ---- */
.login-wrap {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 32px; gap: 18px;
}
.logo { font-size: 56px; }
.login-title { font-size: 22px; font-weight: 600; }
.login-sub { color: var(--text-sub); font-size: 13px; }
.field { width: 100%; }
.field input {
  width: 100%; padding: 13px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text); font-size: 15px; outline: none;
}
.field input:focus { border-color: #07c160; }
.btn {
  width: 100%; padding: 13px; border-radius: 10px; border: none;
  background: #07c160; color: var(--text); font-size: 16px; font-weight: 500;
  cursor: pointer; transition: opacity .15s;
}
.btn:active { opacity: .8; }
.btn.ghost { background: var(--bg-input); color: var(--text); }
.login-err { color: #ff6b6b; font-size: 13px; min-height: 18px; }

/* ---- top bar ---- */
.topbar {
  height: 50px; display: flex; align-items: center; padding: 0 12px;
  background: var(--bg-card); border-bottom: 1px solid #1a1a1a; flex-shrink: 0;
}
.topbar .title { flex: 1; text-align: center; font-weight: 600; font-size: 16px; }
.topbar .icon { font-size: 20px; padding: 6px; cursor: pointer; }

/* ---- bottom tabs (admin) ---- */
.tabs {
  display: flex; background: var(--bg-card); border-top: 1px solid var(--border);
  flex-shrink: 0; height: 54px; position: sticky; bottom: 0; z-index: 100;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; color: var(--text-sub); cursor: pointer; font-size: 11px;
}
.tab.active { color: #07c160; }
.tab .emoji { font-size: 20px; }

/* ---- content ---- */
.page { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
.page.hidden { display: none; }
/* full-height flex containers for list/main pages */
#page-list, #page-main { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

/* date inputs in admin filter rows must be allowed to shrink */
#tab-records input[type="date"], #tab-records input[type="text"] { min-width: 0; }

/* stats cards */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card {
  background: var(--bg-card); border-radius: 12px; padding: 16px;
}
.stat-card .num { font-size: 26px; font-weight: 700; color: #07c160; }
.stat-card .lbl { color: var(--text-sub); font-size: 12px; margin-top: 4px; }

/* list rows */
.row {
  display: flex; align-items: center; padding: 12px 16px; gap: 12px;
  cursor: pointer; border-bottom: 1px solid #222;
}
.row:active { background: #222; }
.avatar-wrap { position: relative; flex-shrink: 0; }
.row .avatar {
  width: 48px; height: 48px; border-radius: 8px;
  background: linear-gradient(135deg, #07c160, #06ad56);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: var(--text);
}
.row .main { flex: 1; min-width: 0; }
.row .name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--text-sub); font-size: 13px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .right { text-align: right; flex-shrink: 0; }
.row .time { color: var(--text-sub); font-size: 12px; }
.badge {
  position: absolute; top: -4px; right: -4px;
  background: #fa5151; color: var(--text);
  font-size: 11px; font-weight: 500;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 2px #1a1a1a;
}

.blacklist-badge {
  position: absolute; bottom: -4px; right: -4px;
  width: 18px; height: 18px;
  background: #1a1a1a; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 2px #1a1a1a;
}
.blacklist-badge svg { width: 14px; height: 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #555; display: inline-block; }
.dot.online { background: #07c160; }
.dot.offline { background: #555; }

/* floating action button */
.fab {
  position: fixed; bottom: 70px; right: calc(50% - 220px + 20px);
  width: 52px; height: 52px; border-radius: 50%; background: #07c160;
  color: var(--text); font-size: 28px; display: flex; align-items: center;
  justify-content: center; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,.4);
  z-index: 50;
}

/* ---- chat (old styles removed; see prototype-aligned block at end) ---- */

/* typing indicator */
.typing-indicator {
  text-align: center; color: var(--text-sub); font-size: 12px; padding: 6px;
  height: 24px;
}

/* modal */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1000;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(30px) scale(.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal {
  background: var(--bg-card); border-radius: 16px; padding: 20px;
  width: 90%; max-width: 420px; max-height: 85vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.5); border: 1px solid var(--border);
  animation: slideUp .25s ease;
  position: relative;
}
.modal h3 {
  text-align: center; font-size: 16px; font-weight: 600;
  margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.modal .field { margin-bottom: 12px; }
.modal .field label { display: block; font-size: 13px; color: var(--text-sub); margin-bottom: 6px; }
.modal .field input, .modal .field textarea, .modal .field select {
  width: 100%; padding: 11px 12px; background: var(--bg-input); border: 1px solid #444;
  border-radius: 8px; color: var(--text); font-size: 15px; outline: none;
}
.modal .field input:focus, .modal .field textarea:focus, .modal .field select:focus { border-color: #07c160; }
.modal .field input::placeholder { color: #666; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions .btn {
  flex: 1; height: 44px; padding: 0; font-size: 15px; border-radius: 10px;
  border: none; cursor: pointer; transition: opacity .15s, transform .1s;
}
.modal-actions .btn:active { transform: scale(.97); opacity: .8; }
.btn.primary { background: #07c160; color: var(--text); }
.btn.secondary { background: #3a3a3a; color: #ddd; }
.btn.danger { background: #fa5151; color: var(--text); }

/* qrcode modal */
.qr-img { display: block; margin: 10px auto; background: #fff; padding: 8px; border-radius: 10px; }
.qr-status { text-align: center; color: var(--text-sub); font-size: 13px; margin-top: 8px; }
.share-link {
  margin: 10px 0; padding: 10px; background: var(--bg); border-radius: 8px;
  font-size: 11px; color: var(--text-sub); word-break: break-all; line-height: 1.5;
}

/* settings list */
.setting-row {
  background: var(--bg-card); border-radius: 10px; padding: 14px; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between;
}
.setting-row .lbl { color: #ddd; }
.switch { position: relative; width: 44px; height: 24px; background: #555; border-radius: 12px; cursor: pointer; transition: background .2s; }
.switch.on { background: #07c160; }
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
  background: #fff; border-radius: 50%; transition: left .2s;
}
.switch.on::after { left: 22px; }

textarea.setting-input {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 10px; font-size: 14px; min-height: 70px; outline: none;
  font-family: inherit;
}

/* rules editor */
.rule-row { display: flex; gap: 6px; margin-bottom: 6px; }
.rule-row input { flex: 1; padding: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
.rule-row .del { background: #d9534f; color: var(--text); border: none; border-radius: 6px; padding: 0 10px; cursor: pointer; }

/* audio player */
.audio-bubble { display: flex; align-items: center; gap: 8px; min-width: 100px; cursor: pointer; }
.audio-bubble .wave { font-size: 14px; }
.audio-bubble .dur { font-size: 12px; opacity: .8; }

/* image preview */
.preview-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.preview-mask img { max-width: 95%; max-height: 95%; }

/* toast */
.toast {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--bg-card); color: var(--text); padding: 12px 22px; border-radius: 10px;
  font-size: 14px; z-index: 2000; opacity: 0; transition: opacity .25s;
  display: flex; align-items: center; gap: 8px; pointer-events: none;
  border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; }
.toast .icon { font-size: 16px; display: inline-flex; align-items: center; margin-right: 4px; }
.toast .icon svg { display: block; }
.topbar .icon svg, .icon-btn svg, .fab svg, .tab .emoji svg { display: block; margin: 0 auto; }
.icon-btn { display: flex; align-items: center; justify-content: center; }

.empty { text-align: center; color: #666; padding: 40px 0; }

/* ============ Chat page (prototype-aligned) ============ */
.chat-header {
  display: flex; align-items: center; padding: 12px 16px;
  background: var(--bg); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.chat-back, .chat-more {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; border-radius: 50%; color: var(--text);
}
.chat-back:active, .chat-more:active { background: var(--bg-card); }
.chat-back svg, .chat-more svg { width: 22px; height: 22px; }
.chat-title { flex: 1; padding: 0 8px; }
.chat-name { font-size: 16px; font-weight: 600; }
.chat-status { font-size: 11px; color: var(--primary); margin-top: 1px; }

.chat-messages { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px; background: var(--bg); }
.msg-time-sep { text-align: center; color: var(--text-sub); font-size: 11px; margin: 6px 0; cursor: pointer; user-select: none; -webkit-user-select: none; transition: opacity 0.15s; }
.msg-time-sep:active { opacity: 0.5; }
.msg-row { display: flex; margin-bottom: 10px; gap: 8px; align-items: flex-start; }
.msg-row.out { flex-direction: row-reverse; }
.msg-avatar-sm {
  width: 36px; height: 36px; border-radius: 6px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), #06ad56);
  display: flex; align-items: center; justify-content: center;
  color: var(--text); font-size: 14px;
}
.msg-row.out .msg-avatar-sm { background: linear-gradient(135deg, #07c160, #06ad56); }
.msg-bubble {
  max-width: 70%; width: fit-content;
  padding: 10px 14px; border-radius: 8px;
  font-size: 15px; line-height: 1.5; position: relative;
  white-space: pre-wrap; word-break: normal; overflow-wrap: break-word;
}
.msg-row.in .msg-bubble { background: var(--bubble-in); color: var(--text); }
.msg-row.out .msg-bubble { background: var(--bubble-out); color: #1a1a1a; }
.msg-bubble img { max-width: 180px; border-radius: 6px; display: block; }
.msg-bubble video { max-width: 180px; border-radius: 6px; display: block; }
.msg-bubble .file-item { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.msg-bubble .file-icon {
  width: 40px; height: 40px; background: rgba(0,0,0,0.1); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.msg-bubble .file-name { font-size: 13px; font-weight: 500; }
.msg-bubble .file-size { font-size: 11px; opacity: 0.7; margin-top: 2px; }
.msg-bubble .voice-item { display: inline-flex; align-items: center; justify-content: flex-start; gap: 6px; min-width: 80px; height: 22px; cursor: pointer; user-select: none; vertical-align: middle; }
.msg-bubble .voice-icon { width: 18px; height: 18px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.msg-bubble .voice-icon svg { display: block; width: 18px; height: 18px; }
.msg-bubble .voice-duration { font-size: 14px; min-width: 24px; line-height: 1; display: flex; align-items: center; }
.msg-bubble .voice-item.playing .voice-icon { animation: voicePulse 0.8s ease-in-out infinite; }
@keyframes voicePulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.2); } }
.sub .preview-voice { color: #ff4d4f; }
.sub .preview-media { color: var(--text-sub); }
.sub .preview-image { color: #b37feb; }
.sub .preview-file { color: #b37feb; }
.vc-card { background: var(--bg); width: 100%; max-width: 500px; border-radius: 16px 16px 0 0; padding: 18px; animation: slideUp .25s ease; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.vc-header { display: flex; justify-content: space-between; align-items: center; font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.vc-close { background: none; border: none; color: var(--text-sub); font-size: 18px; cursor: pointer; }
.vc-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.vc-label { color: var(--text-sub); }
.vc-value { color: var(--text); text-align: right; max-width: 60%; word-break: break-all; }
.vc-save { width: 100%; margin-top: 14px; padding: 10px; background: #07c160; color: #fff; border: none; border-radius: 8px; font-size: 15px; cursor: pointer; }

.chat-input-area {
  display: flex; align-items: flex-end; padding: 8px 12px;
  background: var(--bg); border-top: 1px solid var(--border); flex-shrink: 0;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
.input-icon-btn {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; border-radius: 50%; flex-shrink: 0; color: var(--text-sub);
}
.input-icon-btn:active { background: var(--bg-card); }
.input-icon-btn svg { width: 24px; height: 24px; }
.chat-input {
  flex: 1; padding: 10px 14px; margin: 0 8px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 20px; color: var(--text); font-size: 15px;
  outline: none; max-height: 100px; resize: none; font-family: inherit;
  overflow: hidden; overflow-y: hidden; -webkit-appearance: none; appearance: none;
}
.chat-input:focus { border-color: var(--primary); }
.send-btn {
  width: 36px; height: 36px; background: var(--primary); border: none;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; color: var(--text);
}
.send-btn:active { opacity: 0.8; }
.send-btn svg { width: 20px; height: 20px; }
.send-btn.hidden { display: none; }

.emoji-panel { padding: 12px; background: var(--bg-card); border-top: 1px solid var(--border); max-height: 220px; overflow-y: auto; flex-shrink: 0; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.emoji-item {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: 22px; cursor: pointer; border-radius: 6px;
}
.emoji-item:active { background: var(--bg-input); }

.func-panel { padding: 16px; background: var(--bg-card); border-top: 1px solid var(--border); flex-shrink: 0; }
.func-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.func-item { display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.func-icon {
  width: 52px; height: 52px; background: var(--bg-input); border-radius: 14px;
  display: flex; align-items: center; justify-content: center; margin-bottom: 6px; color: var(--text);
}
.func-icon svg { width: 26px; height: 26px; }
.func-label { font-size: 12px; color: var(--text-sub); }

/* media messages: no bubble background for image/video */
.msg-row.msg-image .msg-bubble,
.msg-row.msg-video .msg-bubble {
  background: none !important;
  padding: 0 !important;
  border-radius: 12px;
}
.msg-row.msg-image img,
.msg-row.msg-video video {
  display: block;
  max-width: 200px;
  max-height: 300px;
  border-radius: 12px;
  object-fit: cover;
}
.msg-row.msg-image img { cursor: pointer; }

/* QR modal */
.qr-modal { background: var(--bg-card);
  border-radius: 20px; width: 90%; max-width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
  border: 1px solid var(--border); animation: slideUp .3s ease; }
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.qr-modal-header { display: flex; justify-content: center; align-items: center; padding: 20px 20px 12px; position: relative; }
.qr-modal-title { font-size: 18px; font-weight: 600; color: var(--text); }
.qr-close-btn { position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-sub); cursor: pointer; padding: 4px; display: flex; }
.qr-close-btn:hover { color: var(--text); }
.qr-modal-body { padding: 0 20px 24px; }
.qr-modal-desc { color: var(--text-sub); font-size: 13px; text-align: center; margin: 0 0 16px; line-height: 1.5; }
.qr-modal-qr { display: flex; justify-content: center; margin: 0 0 18px; }
.qr-modal-qr .qr-modal-code-box {
  background: #fff; padding: 10px; border-radius: 12px;
  border: 4px solid #07c160; display: inline-block;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.qr-modal-qr .qr-modal-code-box img,
.qr-modal-qr .qr-modal-code-box canvas { width: 180px; height: 180px; display: block; }
.qr-link-box { display: flex; align-items: center; gap: 8px; background: var(--bg-input);
  border-radius: 12px; padding: 14px 16px; margin-bottom: 16px; border: 1px solid var(--border); }
.qr-link-text { color: var(--text-sub); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.qr-copy-btn { width: 100%; height: 44px; background: #07c160; color: #fff; border: none;
  border-radius: 12px; font-size: 16px; font-weight: 600; cursor: pointer; }
.qr-copy-btn:active { transform: scale(.98); background: #06ad56; }

/* admin modal */
.admin-modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 2000;
  display: flex; align-items: center; justify-content: center; animation: fadeIn .2s; }
.admin-modal { background: var(--bg-card); border-radius: 20px;
  width: 90%; max-width: 360px; border: 1px solid var(--border); animation: slideUp .3s; }
.admin-modal-header { display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,.08); }
.admin-modal-title { color: var(--text); font-size: 17px; font-weight: 600; }
.admin-modal-close { background: none; border: none; color: var(--text-sub); font-size: 18px; cursor: pointer; }
.admin-modal-body { padding: 16px 20px; }
.admin-modal-body label { display: block; color: var(--text-sub); font-size: 13px; margin: 12px 0 6px; }
.admin-modal-body label:first-child { margin-top: 0; }
.admin-modal-body input, .admin-modal-body textarea {
  width: 100%; background: var(--bg); border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px; padding: 10px 12px; color: var(--text); font-size: 14px; box-sizing: border-box; }
.admin-modal-body textarea { resize: vertical; min-height: 60px; }
.admin-modal-footer { display: flex; gap: 10px; padding: 12px 20px 20px; }
.admin-btn-cancel { flex: 1; height: 40px; background: var(--bg-input); color: #ccc; border: none; border-radius: 10px; font-size: 15px; cursor: pointer; }
.admin-btn-confirm { flex: 1; height: 40px; background: #07c160; color: var(--text); border: none; border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer; }

/* light mode */
body.light-mode { background: #f5f5f5; color: #333; }
body.light-mode .topbar, body.light-mode .tabs { background: #fff; color: #333; }
body.light-mode .conv-item, body.light-mode .setting-row { background: #fff; color: #333; }
body.light-mode .lbl, body.light-mode .title { color: #333; }
body.light-mode input, body.light-mode textarea { background: #fff; color: #333; border-color: #ddd; }

/* theme variables */
:root {
  --card-color: #2a2a2a;
  --sub-text-color: var(--text-sub);
}
body.light-mode {
  --card-color: var(--text);
  --sub-text-color: #666;
}

/* ============ Image viewer (shared) ============ */
.image-viewer-mask {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.image-viewer-img {
  max-width: 90%; max-height: 90%;
  border-radius: 4px; user-select: none;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.image-viewer-close {
  position: absolute; top: max(16px, env(safe-area-inset-top)); right: 16px;
  width: 38px; height: 38px; border-radius: 50%;
  background: rgba(255,255,255,0.18); color: #fff;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  z-index: 10000;
}
.image-viewer-close:active { background: rgba(255,255,255,0.35); }
.image-viewer-close svg { width: 22px; height: 22px; }

/* ============ File item active feedback (shared) ============ */
.file-item { cursor: pointer; transition: opacity .15s ease; }
.file-item:active { opacity: 0.7; }

/* ============ Admin session record modal: bubble styles ============ */
.admin-msg-list { display: flex; flex-direction: column; }
.admin-msg-list .msg-row { display: flex; margin-bottom: 10px; gap: 8px; align-items: flex-start; }
.admin-msg-list .msg-row.out { flex-direction: row-reverse; }
.admin-msg-list .msg-avatar-sm {
  width: 30px; height: 30px; border-radius: 6px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), #06ad56);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px;
}
.admin-msg-list .msg-row.out .msg-avatar-sm { background: linear-gradient(135deg, #07c160, #06ad56); }
.admin-msg-list .msg-bubble {
  max-width: 75%; padding: 9px 12px; border-radius: 8px;
  font-size: 14px; line-height: 1.5; position: relative;
  word-break: break-word; overflow-wrap: break-word;
  background: var(--bubble-in); color: var(--text);
}
.admin-msg-list .msg-row.out .msg-bubble { background: var(--bubble-out); color: #1a1a1a; }
.admin-msg-list .msg-bubble img { max-width: 180px; border-radius: 6px; display: block; cursor: zoom-in; }
.admin-msg-list .msg-bubble video { max-width: 180px; border-radius: 6px; display: block; }
.admin-msg-list .file-item { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.admin-msg-list .file-icon {
  width: 38px; height: 38px; background: rgba(0,0,0,0.12); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.admin-msg-list .file-name { font-size: 13px; font-weight: 500; word-break: break-all; }
.admin-msg-list .file-size { font-size: 11px; opacity: 0.7; margin-top: 2px; }
.admin-msg-list .voice-item { display: inline-flex; align-items: center; justify-content: flex-start; gap: 6px; min-width: 80px; height: 22px; cursor: pointer; user-select: none; vertical-align: middle; }
.admin-msg-list .voice-icon { width: 18px; height: 18px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.admin-msg-list .voice-icon svg { display: block; width: 18px; height: 18px; }
.admin-msg-list .voice-duration { font-size: 14px; min-width: 24px; line-height: 1; display: flex; align-items: center; }
.admin-msg-list .voice-item.playing .voice-icon { animation: voicePulse 0.8s ease-in-out infinite; }
.admin-msg-list .msg-time-sep { text-align: center; color: var(--text-sub); font-size: 11px; margin: 6px 0; cursor: pointer; user-select: none; -webkit-user-select: none; transition: opacity 0.15s; }
.msg-time-sep:active { opacity: 0.5; }

/* === Admin records: fix invisible incoming bubbles === */
/* In dark mode, --bubble-in (#2a2a2a) == --bg-card (#2a2a2a) == modal bg,
   so incoming bubbles blend in. Give them a visible frame. */
.admin-msg-list .msg-row.in .msg-bubble {
  background: #3a3a3a;
}
body.light-mode .admin-msg-list .msg-row.in .msg-bubble {
  background: #f0f0f0;
}
/* Voice bubble: add padding so it looks like a proper chat bubble */
.admin-msg-list .msg-row.msg-voice .msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
}
/* File bubble: ensure it looks like a card */
.admin-msg-list .msg-row.msg-file .msg-bubble {
  padding: 10px 12px;
  border-radius: 12px;
}
/* Image/video: remove bubble padding so media fills the bubble */
.admin-msg-list .msg-row.msg-image .msg-bubble,
.admin-msg-list .msg-row.msg-video .msg-bubble {
  padding: 3px;
  border-radius: 10px;
}

/* === Voice recording mode === */
.voice-record-btn {
  flex: 1; margin: 0 8px; padding: 10px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 20px; text-align: center; font-size: 16px;
  color: var(--text); cursor: pointer; user-select: none;
  -webkit-user-select: none; touch-action: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 500; transition: background 0.1s;
}
.voice-record-btn:active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Recording overlay */
.recording-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5); z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}
.recording-panel {
  background: rgba(40,40,40,0.95); border-radius: 16px;
  padding: 30px 40px; display: flex; flex-direction: column;
  align-items: center; gap: 14px; min-width: 180px;
  transition: background 0.2s;
}
.recording-overlay.cancel-mode .recording-panel {
  background: rgba(200,50,50,0.95);
}
.recording-wave {
  display: flex; align-items: center; gap: 4px; height: 32px;
}
.recording-wave span {
  display: inline-block; width: 4px; background: #07c160;
  border-radius: 2px; animation: wavePulse 1s ease-in-out infinite;
}
.recording-overlay.cancel-mode .recording-wave span {
  background: #fff;
}
.recording-wave span:nth-child(1) { height: 12px; animation-delay: 0s; }
.recording-wave span:nth-child(2) { height: 24px; animation-delay: 0.15s; }
.recording-wave span:nth-child(3) { height: 32px; animation-delay: 0.3s; }
.recording-wave span:nth-child(4) { height: 24px; animation-delay: 0.45s; }
.recording-wave span:nth-child(5) { height: 12px; animation-delay: 0.6s; }
@keyframes wavePulse {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1.2); }
}
.recording-duration {
  font-size: 28px; font-weight: 600; color: #fff;
  font-variant-numeric: tabular-nums;
}
.recording-hint {
  font-size: 13px; color: rgba(255,255,255,0.7);
}
.recording-overlay.cancel-mode .recording-hint {
  color: #fff;
  font-weight: 500;
}


/* ============================================================
   PC 端适配 (min-width: 768px) — 玻璃拟态 + 三栏布局
   ============================================================ */
#spiderweb-bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  width: 100vw; height: 100vh; display: none;
}
/* 安全兜底：pc-sidebar 默认隐藏，仅在 PC 媒体查询中显示 */
#pc-sidebar { display: none; }
/* 防止 SVG 在任何情况下无尺寸渲染成巨大图标 */
#pc-sidebar svg { width: 22px; height: 22px; }
/* PC 欢迎屏默认隐藏（移动端不显示） */
#pc-welcome { display: none; }
@media (min-width: 768px) {
  #spiderweb-bg { display: block; }

  html, body { height: 100vh; overflow: hidden; }
  body { background: var(--bg); }

  /* --- 主容器：全宽 flex 行 --- */
  #app {
    max-width: none !important;
    width: 100%; height: 100vh;
    flex-direction: row;
    background: transparent;
    position: relative; z-index: 1;
  }

  /* --- 登录页 PC 居中 --- */
  #page-login { width: 100%; max-width: 420px; margin: 0 auto; z-index: 2; position: relative; }
  #page-login:not(.hidden) ~ * { display: none !important; }

  /* --- PC 左侧图标导航栏 (60px) --- */
  #pc-sidebar {
    display: flex !important;
    width: 60px; flex-shrink: 0;
    flex-direction: column; align-items: center;
    padding: 12px 0;
    background: rgba(30,30,30,0.75);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid rgba(255,255,255,0.06);
    z-index: 10;
  }
  body.light-mode #pc-sidebar {
    background: rgba(255,255,255,0.75);
    border-right: 1px solid rgba(0,0,0,0.06);
  }
  .pc-sidebar-logo {
    width: 40px; height: 40px; border-radius: 12px;
    background: linear-gradient(135deg, #07c160, #06ad56);
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 20px; flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(7,193,96,0.3);
  }
  .pc-sidebar-logo svg { width: 22px; height: 22px; color: #fff; }
  .pc-sidebar-nav { display: flex; flex-direction: column; gap: 8px; flex: 1; }
  .pc-nav-btn {
    width: 44px; height: 44px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--text-sub);
    transition: all 0.2s ease;
    position: relative;
  }
  .pc-nav-btn svg { width: 22px; height: 22px; }
  .pc-nav-btn:hover { background: rgba(7,193,96,0.12); color: #07c160; }
  .pc-nav-btn.active { background: rgba(7,193,96,0.18); color: #07c160; }
  /* 侧边栏"扫码接入"主 CTA：绿色渐变突出 */
  .pc-nav-btn.pc-nav-scan {
    background: linear-gradient(135deg, #07c160, #06ad56);
    color: #fff;
    box-shadow: 0 4px 12px rgba(7,193,96,0.3);
  }
  .pc-nav-btn.pc-nav-scan:hover {
    background: linear-gradient(135deg, #06ad56, #059a4c);
    color: #fff;
    transform: translateY(-1px);
  }
  .pc-sidebar-bottom { display: flex; flex-direction: column; align-items: center; gap: 8px; }
  .pc-status-btn {
    width: 44px; height: 44px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--text-sub); transition: all 0.2s ease;
  }
  .pc-status-btn svg { width: 22px; height: 22px; }
  .pc-status-btn:hover { background: rgba(7,193,96,0.12); color: #07c160; }
  .pc-status-dot {
    position: absolute; bottom: 4px; right: 4px;
    width: 10px; height: 10px; border-radius: 50%;
    background: #07c160; border: 2px solid var(--bg);
  }
  .pc-logout-btn {
    width: 44px; height: 44px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--text-sub); transition: all 0.2s ease;
  }
  .pc-logout-btn svg { width: 22px; height: 22px; }
  .pc-logout-btn:hover { background: rgba(250,81,81,0.12); color: #fa5151; }

  /* --- 中栏：会话列表 (300px) --- */
  #page-list {
    flex: 0 0 300px; width: 300px;
    display: flex !important;
    background: rgba(30,30,30,0.6);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-right: 1px solid rgba(255,255,255,0.06);
  }
  body.light-mode #page-list {
    background: rgba(255,255,255,0.6);
    border-right: 1px solid rgba(0,0,0,0.06);
  }
  /* 隐藏 PC 端 topbar 中的设置按钮（功能移到侧边栏）；保留扫码接入按钮 #topbar-scan-btn */
  #page-list .topbar .icon:not(#topbar-scan-btn) { display: none !important; }
  /* PC 端恢复 topbar 扫码接入按钮（绿色主 CTA） */
  #page-list .topbar #topbar-scan-btn {
    display: inline-flex !important;
    align-items: center; justify-content: center;
    width: 36px; height: 36px; padding: 6px;
    border-radius: 10px; color: var(--text-sub);
    transition: all 0.2s ease;
  }
  #page-list .topbar #topbar-scan-btn:hover {
    background: rgba(7,193,96,0.12); color: #07c160;
  }
  #page-list .topbar {
    background: transparent;
    border-bottom: 1px solid rgba(255,255,255,0.06);
  }
  body.light-mode #page-list .topbar { border-bottom-color: rgba(0,0,0,0.06); }
  #page-list > div[style*="padding:8px"] {
    background: transparent !important;
  }
  /* PC 端隐藏 agent 页底部空 tabs（不承载内容，仅移动端占位用） */
  #page-list > .tabs { display: none; }
  #search-box {
    background: rgba(255,255,255,0.08) !important;
    border: 1px solid transparent !important;
  }
  body.light-mode #search-box { background: rgba(0,0,0,0.05) !important; }

  /* 会话列表项 hover/选中 */
  #conv-list .row {
    border-bottom: none;
    border-radius: 10px;
    margin: 2px 8px;
    padding: 10px 12px;
    transition: background 0.15s ease;
  }
  #conv-list .row:hover { background: rgba(7,193,96,0.08); }
  #conv-list .row.active {
    background: rgba(7,193,96,0.15);
    border-left: 3px solid #07c160;
  }
  #conv-list .row:active { background: rgba(7,193,96,0.12); }

  /* --- 右栏：聊天区 (flex:1) --- */
  #page-chat {
    flex: 1; min-width: 0;
    background: rgba(26,26,26,0.4);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  }
  body.light-mode #page-chat { background: rgba(245,245,245,0.5); }
  #page-chat.hidden { display: none !important; }
  /* PC 端未选中会话时的欢迎屏 */
  #pc-welcome {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    background: rgba(26,26,26,0.4);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    color: var(--text-sub); gap: 16px;
  }
  body.light-mode #pc-welcome { background: rgba(245,245,245,0.5); }
  #pc-welcome svg { width: 64px; height: 64px; opacity: 0.3; color: var(--text-sub); }
  #pc-welcome .pc-welcome-title { font-size: 18px; font-weight: 600; color: var(--text-sub); }
  #pc-welcome .pc-welcome-sub { font-size: 13px; opacity: 0.7; }
  /* 欢迎屏"扫码接入访客"主按钮：玻璃拟态 + 绿色主色 */
  .pc-welcome-scan-btn {
    width: auto; max-width: 320px;
    margin: 8px auto 0;
    padding: 13px 36px;
    font-size: 15px; font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, rgba(7,193,96,0.92), rgba(6,173,86,0.92));
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 14px;
    cursor: pointer;
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 8px 24px rgba(7,193,96,0.35);
    transition: all 0.2s ease;
  }
  .pc-welcome-scan-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(7,193,96,0.45);
    background: linear-gradient(135deg, rgba(6,173,86,1), rgba(5,154,76,1));
  }
  .pc-welcome-scan-btn:active { transform: translateY(0) scale(0.98); }
  .pc-welcome-hint { font-size: 12px; color: var(--text-sub); opacity: 0.55; margin-top: 2px; }
  /* 隐藏 PC 端聊天头部的返回按钮 */
  #page-chat .chat-back { display: none !important; }
  .chat-header {
    background: transparent;
    border-bottom: 1px solid rgba(255,255,255,0.06);
  }
  body.light-mode .chat-header { border-bottom-color: rgba(0,0,0,0.06); }
  .chat-messages { background: transparent !important; }
  .chat-input-area {
    background: transparent;
    border-top: 1px solid rgba(255,255,255,0.06);
    padding-bottom: 12px;
  }
  body.light-mode .chat-input-area { border-top-color: rgba(0,0,0,0.06); }

  /* 消息气泡最大宽度 60% */
  .msg-bubble { max-width: 60% !important; }
  .chat-input {
    min-height: 40px;
    padding: 10px 16px;
  }
  .send-btn { width: 40px; height: 40px; }
  .input-icon-btn { width: 40px; height: 40px; }

  /* --- 设置/快捷回复/关键词回复 作为覆盖右侧面板 --- */
  #page-settings, #page-qr-manage, #page-ar-manage {
    position: fixed !important;
    top: 0; right: 0; bottom: 0;
    width: calc(100% - 360px); /* 60 sidebar + 300 list */
    max-width: none !important;
    z-index: 50;
    background: rgba(26,26,26,0.92) !important;
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    overflow-y: auto;
    padding: 24px !important;
  }
  body.light-mode #page-settings,
  body.light-mode #page-qr-manage,
  body.light-mode #page-ar-manage {
    background: rgba(255,255,255,0.92) !important;
  }
  #page-settings.hidden, #page-qr-manage.hidden, #page-ar-manage.hidden { display: none !important; }
  #page-settings .btn { max-width: 400px; }
  #page-settings .setting-row { max-width: 600px; }

  /* --- 滚动条美化 --- */
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15); border-radius: 3px;
  }
  ::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }
  body.light-mode ::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); }
  body.light-mode ::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }

  /* ============================================================
     超管后台 PC 端
     ============================================================ */
  #page-main { flex-direction: row; }
  #page-main .topbar { display: none; }
  #page-main .tabs {
    flex-direction: column;
    width: 200px; height: 100vh;
    position: fixed; left: 0; top: 0; bottom: 0;
    border-top: none; border-right: 1px solid rgba(255,255,255,0.06);
    border-bottom: none;
    background: rgba(30,30,30,0.75);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    padding-top: 20px;
    z-index: 10;
  }
  body.light-mode #page-main .tabs {
    background: rgba(255,255,255,0.75);
    border-right: 1px solid rgba(0,0,0,0.06);
  }
  #page-main .tab {
    flex-direction: row;
    justify-content: flex-start;
    padding: 12px 20px;
    gap: 12px;
    font-size: 14px;
    height: auto;
    margin: 2px 8px;
    border-radius: 10px;
    transition: all 0.15s ease;
  }
  #page-main .tab:hover { background: rgba(7,193,96,0.08); }
  #page-main .tab.active { background: rgba(7,193,96,0.15); }
  #page-main .page {
    margin-left: 200px;
    width: calc(100% - 200px);
    padding: 24px;
  }
  .stats { grid-template-columns: repeat(4, 1fr) !important; gap: 16px; }
  .stat-card { padding: 20px; }
  .stat-card .num { font-size: 32px; }
  #trend-chart { height: 200px !important; }
  .fab { bottom: 30px !important; right: 30px !important; }
}
