/* WATransChat Admin — Intercom / Crisp / Zendesk inbox pattern */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --inbox-w: 320px;
  --info-w: 300px;
  --header-h: 60px;
  --bg-app: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-chat: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-secondary: #64748b;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, .08);
  --agent-bubble-bg: #dbeafe;
  --ai-bubble-bg: #ecfdf5;
  --visitor-bubble-bg: #ffffff;
  --ai-font-size: 14px;
  --agent-font-size: 14px;
  --visitor-font-size: 14px;
}

* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: rgba(0,0,0,.12) transparent; }

.lucide { stroke: currentColor; fill: none; flex-shrink: 0; }
.icon-sm { width: 18px; height: 18px; }
.icon-md { width: 20px; height: 20px; }
.icon-lg { width: 32px; height: 32px; stroke-width: 1.5; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb { background: rgba(0,0,0,.1); border-radius: 999px; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-app);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.layout {
  display: flex;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-app);
}

/* ── Inbox panel ── */
.inbox-panel,
.sidebar {
  width: var(--inbox-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.inbox-header {
  padding: 16px 14px 12px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.inbox-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
}

.inbox-brand-name {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  line-height: 1.3;
}

.inbox-brand-name .brand-accent {
  color: var(--primary);
  font-weight: 700;
}

.inbox-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.inbox-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.2;
  color: var(--text);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: #f8fafc; color: var(--text); }

.inbox-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: #f1f5f9;
  padding: 2px 7px;
  border-radius: 999px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}

.conv-search-wrap {
  padding: 4px 12px 10px;
  flex-shrink: 0;
  position: relative;
}

.conv-search-wrap input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: #f8fafc;
  transition: border-color .15s, box-shadow .15s, background .15s;
}

.conv-search-wrap input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.conv-search-wrap::before {
  content: "";
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  opacity: .4;
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-4.35-4.35M11 18a7 7 0 100-14 7 7 0 000 14z'/%3E%3C/svg%3E") center/contain no-repeat;
}

.conv-filters {
  display: flex;
  gap: 4px;
  padding: 0 12px 10px;
  flex-shrink: 0;
  overflow-x: auto;
}

.conv-filters button {
  padding: 5px 11px;
  border-radius: 6px;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all .12s;
}

.conv-filters button:hover { background: #f1f5f9; color: var(--text); }
.conv-filters button.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.conv-list,
#conv-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.conv-item {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background .1s;
  align-items: flex-start;
  position: relative;
}

.conv-item:hover { background: #f8fafc; }
.conv-item.active {
  background: var(--primary-soft);
  box-shadow: inset 3px 0 0 var(--primary);
}

.conv-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
  color: #3730a3;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.conv-avatar .online-ring {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #94a3b8;
}

.conv-avatar .online-ring.on { background: var(--success); }

.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 2px; }
.conv-top .name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-top .meta-time { font-size: 11px; color: var(--text-secondary); flex-shrink: 0; display: flex; align-items: center; gap: 4px; }
.conv-preview { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; display: flex; align-items: center; gap: 4px; }
.conv-extra { font-size: 11px; color: #94a3b8; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.status-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.status-tag.ai { background: #ecfdf5; color: #047857; }
.status-tag.agent { background: #eff6ff; color: #1d4ed8; }
.status-tag.closed { background: #f1f5f9; color: #64748b; }

.chat-actions .menu-wrap { position: relative; flex-shrink: 0; }

.chat-actions .menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  color: var(--text);
  transition: all .12s;
}
.chat-actions .menu-btn:hover { background: #f8fafc; border-color: #cbd5e1; }
.chat-actions .menu-btn .lucide { width: 16px; height: 16px; }

.chat-actions .dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 130px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  z-index: 30;
  overflow: hidden;
}
.chat-actions .dropdown-menu.show { display: block; }
.chat-actions .dropdown-menu button {
  width: 100%;
  border: none;
  background: #fff;
  text-align: left;
  padding: 9px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.chat-actions .dropdown-menu button:hover { background: #f8fafc; }
.chat-actions .dropdown-menu button.danger { color: var(--danger); }

.unread-badge {
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Workspace ── */
.workspace,
.main {
  flex: 1;
  display: flex;
  min-width: 0;
  background: var(--bg-surface);
  position: relative;
}

.chat-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-chat);
  border-right: 1px solid var(--border);
}

.chat-header {
  height: var(--header-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-surface);
  flex-shrink: 0;
  gap: 12px;
}

.chat-header .title-wrap {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
  gap: 10px;
}

.chat-header .visitor-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
  color: #3730a3;
  font-weight: 700;
  font-size: 13px;
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-header.has-conv .visitor-avatar { display: flex; }
.chat-header .title-block { min-width: 0; }
.chat-header .title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat-header .title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header .title .country { font-size: 13px; color: var(--text-secondary); font-weight: 400; }
.chat-header .subtitle { font-size: 12px; color: var(--text-secondary); margin-top: 1px; display: flex; align-items: center; gap: 5px; }
.chat-header .online-dot { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; }
.chat-header .online-dot.on { background: var(--success); }

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}
.status-pill.status-ai { background: #ecfdf5; color: #047857; }
.status-pill.status-agent { background: #eff6ff; color: #1d4ed8; }
.status-pill.status-closed { background: #f1f5f9; color: #64748b; }

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chat-header .btn-back-mobile,
.chat-header .btn-info-mobile {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  padding: 0;
}
.chat-header .btn-info-mobile .lucide,
.chat-header .btn-back-mobile .lucide { width: 18px; height: 18px; }

.chat-actions { display: flex; gap: 6px; flex-shrink: 0; }

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: all .12s;
}
.btn-action .lucide { width: 16px; height: 16px; flex-shrink: 0; }
.btn-action:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-action.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-action.primary:hover { background: var(--primary-hover); }

#handoff-banner {
  display: none;
  padding: 10px 16px;
  background: #fffbeb;
  color: #92400e;
  font-size: 13px;
  border-bottom: 1px solid #fde68a;
  flex-shrink: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  min-height: 0;
}

.messages-inner { max-width: 720px; margin: 0 auto; }

.msg { margin-bottom: 14px; max-width: 75%; display: flex; flex-direction: column; }
.msg.visitor { margin-right: auto; align-items: flex-start; }
.msg.agent, .msg.ai { margin-left: auto; align-items: flex-end; }

.msg .bubble {
  display: inline-block;
  max-width: 100%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  text-align: left;
  word-wrap: break-word;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  box-shadow: var(--shadow-sm);
}

.msg .bubble a {
  color: #2563eb;
  text-decoration: underline;
  word-break: break-all;
}

.msg .bubble a:hover {
  color: #1d4ed8;
}

.msg.visitor .bubble {
  background: var(--visitor-bubble-bg, #fff);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  font-size: var(--visitor-font-size, 14px);
}

.msg.agent .bubble {
  background: var(--agent-bubble-bg, #dbeafe);
  color: #1e3a5f;
  border-bottom-right-radius: 4px;
  font-size: var(--agent-font-size, 14px);
}

.msg.ai .bubble {
  background: var(--ai-bubble-bg, #ecfdf5);
  color: #14532d;
  border-bottom-right-radius: 4px;
  font-size: var(--ai-font-size, 14px);
}

.msg .meta { font-size: 11px; color: #94a3b8; margin-top: 4px; padding: 0 2px; }

.msg .bubble .quote-preview {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  padding: 6px;
  border-radius: 6px;
  background: #f2f2f7;
  cursor: pointer;
  text-align: left;
  width: 100%;
  min-width: min(260px, 72%);
  box-sizing: border-box;
}
.msg .bubble:has(.quote-preview) {
  min-width: min(280px, 78%);
}
.msg .bubble .quote-preview .quote-bar {
  width: 3px;
  border-radius: 2px;
  background: #25D366;
  flex-shrink: 0;
}
.msg .bubble .quote-preview .quote-body { min-width: 0; flex: 1; }
.msg .bubble .quote-preview .quote-sender {
  font-size: 12px;
  font-weight: 700;
  color: #25D366;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg .bubble .quote-preview .quote-text {
  font-size: 12px;
  color: #64748b;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg .bubble.quote-jump-highlight {
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.55);
  transition: box-shadow 0.2s ease;
}

.admin-reply-bar {
  display: none;
  align-items: stretch;
  gap: 8px;
  padding: 8px 16px 0;
  background: var(--surface, #fff);
  border-top: 1px solid var(--border, #e2e8f0);
  flex-shrink: 0;
}
.admin-reply-bar.show { display: flex; }
.admin-reply-bar-main {
  flex: 1;
  min-width: 0;
  border-left: 3px solid #25D366;
  padding-left: 8px;
}
.admin-reply-bar-title {
  font-size: 12px;
  font-weight: 700;
  color: #25D366;
}
.admin-reply-bar-text {
  font-size: 12px;
  color: #64748b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-reply-bar-close {
  border: none;
  background: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--text-secondary);
  min-height: 280px;
}

.chat-empty-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.chat-empty-icon .lucide { color: #94a3b8; }
.chat-empty h3 { margin: 0 0 8px; font-size: 17px; color: var(--text); font-weight: 600; }
.chat-empty p { margin: 0; font-size: 14px; max-width: 300px; line-height: 1.55; }

#peer-typing-bar {
  display: none;
  padding: 4px 16px 0;
  font-size: 12px;
  color: var(--text-secondary);
  font-style: italic;
  flex-shrink: 0;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.chat-composer {
  padding: 12px 16px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.composer-inner { max-width: 720px; margin: 0 auto; }

.chat-input {
  display: flex;
  gap: 6px;
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 8px;
  transition: border-color .15s, box-shadow .15s;
}

.chat-input:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
  background: #fff;
}

.chat-input textarea {
  flex: 1;
  margin: 0;
  border: none;
  background: transparent;
  font-size: 14px;
  resize: none;
  height: 24px;
  min-height: 24px;
  max-height: 120px;
  line-height: 24px;
  padding: 0 4px;
  font-family: inherit;
  box-sizing: border-box;
  overflow: hidden;
  vertical-align: top;
}

.chat-input textarea:focus { outline: none; }

.chat-input button {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .12s;
  flex-shrink: 0;
}

.chat-input .btn-attach { background: transparent; color: var(--text-secondary); }
.chat-input .btn-attach:hover { background: #e2e8f0; color: var(--text); }
.chat-input #btn-send { background: var(--primary); color: #fff; }
.chat-input #btn-send:hover { background: var(--primary-hover); }
.chat-input #btn-send:disabled { opacity: .5; cursor: not-allowed; }
.chat-input button .lucide { display: block; }

/* ── Info panel ── */
.info-col {
  width: var(--info-w);
  background: var(--bg-surface);
  overflow-y: auto;
  flex-shrink: 0;
}

.info-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 20px;
  color: var(--text-secondary);
  min-height: 200px;
  height: 100%;
}

.info-empty .lucide { width: 40px; height: 40px; color: #cbd5e1; margin-bottom: 12px; }
.info-empty p { margin: 0 0 4px; font-size: 14px; font-weight: 500; color: var(--text); }
.info-empty span { font-size: 12px; }

.info-profile { padding: 20px 16px; text-align: center; border-bottom: 1px solid var(--border); }
.info-profile .big-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
  color: #3730a3;
  font-weight: 700;
  font-size: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}
.info-profile .profile-name { font-weight: 700; font-size: 15px; }
.info-profile .profile-meta { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

.info-col .section { padding: 14px 16px; border-bottom: 1px solid #f1f5f9; }
.info-col .section h3 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.info-col .kv { font-size: 13px; color: var(--text); line-height: 1.65; }
.info-col .kv-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid #f8fafc;
}
.info-col .kv-row:last-child { border-bottom: none; }
.info-col .kv-row .k { color: var(--text-secondary); flex-shrink: 0; }
.info-col .kv-row .v { text-align: right; word-break: break-all; }
.info-col a { color: var(--primary); text-decoration: none; }
.info-col a:hover { text-decoration: underline; }

.info-drawer-backdrop { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 200; }
.info-drawer-backdrop.show { display: block; }

.info-drawer {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  width: min(320px, 92vw);
  height: 100dvh;
  background: var(--bg-surface);
  z-index: 201;
  box-shadow: -8px 0 32px rgba(0,0,0,.12);
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .25s ease;
}
.info-drawer.show { display: block; transform: translateX(0); }

.info-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}
.info-drawer-head button { border: none; background: transparent; font-size: 22px; cursor: pointer; color: var(--text-secondary); line-height: 1; }

/* ── Settings ── */
.settings-page {
  position: absolute;
  inset: 0;
  background: var(--bg-surface);
  display: none;
  z-index: 150;
}

.settings-layout { display: flex; height: 100%; }

.settings-nav {
  width: 200px;
  border-right: 1px solid var(--border);
  background: #f8fafc;
  padding: 20px 12px;
  flex-shrink: 0;
}

.settings-nav .nav-title {
  font-weight: 700;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 0 10px 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.settings-nav button {
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
}
.settings-nav button:hover { background: #f1f5f9; }
.settings-nav button.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.settings-content {
  flex: 1;
  padding: 28px 32px;
  overflow-y: auto;
  background: #fff;
}

.settings-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.settings-top-text { min-width: 0; }
.settings-top .title {
  margin: 0;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -.02em;
  color: var(--text);
}
.settings-subtitle {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.settings-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* 设置页统一按钮 */
.settings-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  font-family: inherit;
  line-height: 1.2;
  transition: background .12s, border-color .12s, color .12s;
  white-space: nowrap;
}
.settings-btn:hover { background: #f8fafc; border-color: #cbd5e1; }
.settings-btn:disabled { opacity: .55; cursor: not-allowed; }
.settings-btn--primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.settings-btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.settings-btn--secondary { background: #fff; }

.form { max-width: 640px; }

.group {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.group-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.group-desc {
  margin: 4px 0 16px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.form-field { margin-bottom: 14px; }
.form-field:last-child { margin-bottom: 0; }

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-field input[type="text"],
.form-field input[type="url"],
.form-field input[type="password"],
.form-field input[type="number"],
.form-field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .12s, box-shadow .12s;
}
.form-field input:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}
.form-field textarea {
  min-height: 140px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}

.form-hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.msg-sound-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-sound-option {
  display: block;
  cursor: pointer;
}

.msg-sound-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.msg-sound-option-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  transition: border-color .12s, box-shadow .12s, background .12s;
}

.msg-sound-option input:checked + .msg-sound-option-body {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
  background: rgba(37, 99, 235, .04);
}

.msg-sound-option-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.btn-sound-preview {
  flex-shrink: 0;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
}

.btn-sound-preview:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(37, 99, 235, .04);
}

.avatar-field {
  display: flex;
  align-items: center;
  gap: 12px;
}
.avatar-field input { flex: 1; min-width: 0; }
.avatar-preview {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  flex-shrink: 0;
  background: #f1f5f9;
}

.bubble-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bubble-grid-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #f1f5f9;
}
.bubble-grid-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
  min-width: 72px;
}
.bubble-grid-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.input-color {
  width: 40px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: #fff;
}
.input-narrow {
  width: 64px !important;
  padding: 8px 10px !important;
  text-align: center;
}
.input-unit {
  font-size: 12px;
  color: var(--text-secondary);
}

.form-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #f1f5f9;
}
.form-toggle-text { flex: 1; min-width: 0; }
.form-toggle-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.form-toggle-row .form-hint { margin-top: 4px; }

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  transition: background .2s;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider::before { transform: translateX(20px); }

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.form-inline-rule {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #f1f5f9;
  font-size: 14px;
  color: var(--text);
}
.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500;
}
.checkbox-inline input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}
.form-inline-text { color: var(--text-secondary); font-size: 13px; }

.status-text {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 10px 12px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #f1f5f9;
}

.form-code-block {
  margin: 12px 0 0;
  max-height: 220px;
  overflow: auto;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
}
.form-code-block[hidden] { display: none !important; }

/* 兼容旧表单类名（若残留） */
.form .row { display: none; }
.form .hint { display: none; }
.color-setting-wrap { display: none; }

.empty { color: var(--text-secondary); text-align: center; padding: 40px 20px; font-size: 13px; }

/* ── Login ── */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(145deg, #0f172a 0%, #1e3a8a 50%, #2563eb 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.login-card {
  width: 400px;
  max-width: 92vw;
  background: #fff;
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 24px 48px rgba(0,0,0,.25);
}

.login-brand { text-align: center; margin-bottom: 24px; }
.login-logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0; font-size: 14px; color: var(--text-secondary); }
.login-card .row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.login-card label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.login-card input {
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.login-card button {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.login-card button:hover { background: var(--primary-hover); }
.login-card button:disabled { opacity: .6; cursor: not-allowed; }
.login-error { margin-top: 8px; font-size: 13px; color: var(--danger); min-height: 18px; }

#toast-root {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: min(360px, calc(100vw - 32px));
}
.toast-item {
  pointer-events: auto;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  animation: toastIn .2s ease;
}
.toast-item.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.toast-item.success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

#image-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.85);
  z-index: 99999;
  align-items: center;
  justify-content: center;
  padding: 20px;
  cursor: zoom-out;
}
#image-lightbox.show { display: flex; }
#image-lightbox img { max-width: 96vw; max-height: 92vh; border-radius: 12px; box-shadow: 0 16px 48px rgba(0,0,0,.5); }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .info-col { display: none !important; }
  .chat-header .btn-info-mobile { display: inline-flex; }
}

@media (max-width: 900px) {
  .inbox-panel, .sidebar { width: 100%; }
  .workspace, .main { display: none; }
  .layout.mobile-chat-open .inbox-panel,
  .layout.mobile-chat-open .sidebar { display: none; }
  .layout.mobile-chat-open .workspace,
  .layout.mobile-chat-open .main { display: flex; flex: 1; width: 100%; }
  .chat-header .btn-back-mobile { display: inline-flex; }
  .settings-page { z-index: 160; }
  .settings-nav {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 10px;
  }
  .settings-nav .nav-title { display: none; }
  .settings-nav button { width: auto; white-space: nowrap; }
  .settings-layout { flex-direction: column; }
  .settings-top { flex-direction: column; align-items: stretch; }
  .settings-actions { justify-content: flex-end; }
  .form-toggle-row { flex-direction: column; align-items: flex-start; }
  .bubble-grid-item { flex-direction: column; align-items: flex-start; }
}

@media (min-width: 901px) {
  .layout.mobile-chat-open .inbox-panel,
  .layout.mobile-chat-open .sidebar { display: flex; }
}
