/* =============================================================================
   ChatCrypt – 端到端加密聊天室 UI 样式表
   ============================================================================= */

/* ---- 主题变量 ---- */
:root {
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --bg0: #eef2ff;
  --bg1: #f8fafc;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #ffffff;
  --text: #0f172a;
  --text-secondary: #475569;
  --muted: #64748b;
  --border: rgba(148, 163, 184, 0.3);
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.1);
  --accent-glow: rgba(79, 70, 229, 0.25);
  --me-start: #e0e7ff;
  --me-end: #dbeafe;
  --them: #f1f5f9;
  --them-border: rgba(148, 163, 184, 0.4);
  --system-bg: linear-gradient(145deg, #fef9c3 0%, #ffedd5 100%);
  --danger: #dc2626;
  --success: #059669;
  --success-soft: rgba(16, 185, 129, 0.1);
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.1);
  --shadow-xl: 0 20px 60px rgba(15, 23, 42, 0.12);
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

html[data-theme="dark"] {
  --bg0: #020617;
  --bg1: #0b1121;
  --panel: rgba(15, 23, 42, 0.85);
  --panel-solid: #111827;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --muted: #748099;
  --border: rgba(71, 85, 105, 0.5);
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-soft: rgba(129, 140, 248, 0.12);
  --accent-glow: rgba(129, 140, 248, 0.2);
  --me-start: #312e81;
  --me-end: #1e3a8a;
  --them: #1e293b;
  --them-border: rgba(100, 116, 139, 0.45);
  --system-bg: linear-gradient(145deg, #422006 0%, #451a03 100%);
  --danger: #fca5a5;
  --success: #6ee7b7;
  --success-soft: rgba(16, 185, 129, 0.12);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* ---- Ocean ---- */
html[data-theme="ocean"] {
  --bg0: #0a192f;
  --bg1: #0d2137;
  --panel: rgba(13, 33, 55, 0.9);
  --panel-solid: #112240;
  --text: #ccd6f6;
  --text-secondary: #8892b0;
  --muted: #6a7b99;
  --border: rgba(100, 140, 180, 0.25);
  --accent: #64ffda;
  --accent-hover: #7dffeb;
  --accent-soft: rgba(100, 255, 218, 0.1);
  --accent-glow: rgba(100, 255, 218, 0.2);
  --me-start: #1a3a5c;
  --me-end: #0d2d4a;
  --them: #172a45;
  --them-border: rgba(100, 140, 180, 0.3);
  --system-bg: linear-gradient(145deg, #1a3a5c 0%, #0d2d4a 100%);
  --danger: #ff8a80;
  --success: #64ffda;
  --success-soft: rgba(100, 255, 218, 0.1);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.45);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.55);
}

/* ---- Forest ---- */
html[data-theme="forest"] {
  --bg0: #0d1f0d;
  --bg1: #142814;
  --panel: rgba(20, 40, 20, 0.88);
  --panel-solid: #1a3a1a;
  --text: #d4e8d4;
  --text-secondary: #8fb88f;
  --muted: #6a946a;
  --border: rgba(100, 160, 100, 0.25);
  --accent: #86efac;
  --accent-hover: #a5f5c0;
  --accent-soft: rgba(134, 239, 172, 0.1);
  --accent-glow: rgba(134, 239, 172, 0.2);
  --me-start: #1e4a2e;
  --me-end: #163a20;
  --them: #1a3624;
  --them-border: rgba(100, 160, 100, 0.3);
  --system-bg: linear-gradient(145deg, #2a4a20 0%, #1a3618 100%);
  --danger: #fca5a5;
  --success: #86efac;
  --success-soft: rgba(134, 239, 172, 0.1);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.45);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.55);
}

/* ---- Sunset ---- */
html[data-theme="sunset"] {
  --bg0: #1a0a1e;
  --bg1: #2d1225;
  --panel: rgba(45, 18, 37, 0.88);
  --panel-solid: #3a1530;
  --text: #fce4ec;
  --text-secondary: #ce93a8;
  --muted: #a07080;
  --border: rgba(180, 100, 130, 0.25);
  --accent: #ff6f91;
  --accent-hover: #ff8fae;
  --accent-soft: rgba(255, 111, 145, 0.12);
  --accent-glow: rgba(255, 111, 145, 0.2);
  --me-start: #4a1535;
  --me-end: #3a0e28;
  --them: #2d1530;
  --them-border: rgba(180, 100, 130, 0.3);
  --system-bg: linear-gradient(145deg, #4a2020 0%, #3a1028 100%);
  --danger: #ff8a80;
  --success: #a5d6a7;
  --success-soft: rgba(165, 214, 167, 0.1);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.45);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.55);
}

/* ---- Midnight ---- */
html[data-theme="midnight"] {
  --bg0: #0c0015;
  --bg1: #140025;
  --panel: rgba(20, 0, 37, 0.9);
  --panel-solid: #1a003a;
  --text: #e8d5f5;
  --text-secondary: #b388cc;
  --muted: #8a60a5;
  --border: rgba(140, 80, 200, 0.25);
  --accent: #c084fc;
  --accent-hover: #d4a5ff;
  --accent-soft: rgba(192, 132, 252, 0.12);
  --accent-glow: rgba(192, 132, 252, 0.2);
  --me-start: #2a0060;
  --me-end: #1a0045;
  --them: #1a0035;
  --them-border: rgba(140, 80, 200, 0.3);
  --system-bg: linear-gradient(145deg, #2a1050 0%, #1a0035 100%);
  --danger: #fca5a5;
  --success: #86efac;
  --success-soft: rgba(134, 239, 172, 0.1);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 60px rgba(0, 0, 0, 0.6);
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  font-family: var(--font);
  color: var(--text);
  letter-spacing: 0.01em;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(99, 102, 241, 0.15), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(14, 165, 233, 0.1), transparent 50%),
    linear-gradient(180deg, var(--bg0) 0%, var(--bg1) 45%, var(--bg1) 100%);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
html[data-theme="dark"] body {
  background:
    radial-gradient(1000px 500px at 15% 0%, rgba(79, 70, 229, 0.18), transparent 55%),
    radial-gradient(800px 400px at 100% 10%, rgba(14, 165, 233, 0.06), transparent 50%),
    linear-gradient(180deg, var(--bg0) 0%, var(--bg1) 100%);
}
html[data-theme="ocean"] body {
  background:
    radial-gradient(1000px 500px at 10% 0%, rgba(100, 255, 218, 0.08), transparent 55%),
    radial-gradient(800px 400px at 100% 10%, rgba(0, 150, 255, 0.06), transparent 50%),
    linear-gradient(180deg, var(--bg0) 0%, var(--bg1) 100%);
}
html[data-theme="forest"] body {
  background:
    radial-gradient(1000px 500px at 10% 0%, rgba(134, 239, 172, 0.06), transparent 55%),
    radial-gradient(800px 400px at 100% 10%, rgba(34, 197, 94, 0.05), transparent 50%),
    linear-gradient(180deg, var(--bg0) 0%, var(--bg1) 100%);
}
html[data-theme="sunset"] body {
  background:
    radial-gradient(1000px 500px at 10% 0%, rgba(255, 111, 145, 0.1), transparent 55%),
    radial-gradient(800px 400px at 100% 10%, rgba(255, 167, 38, 0.06), transparent 50%),
    linear-gradient(180deg, var(--bg0) 0%, var(--bg1) 100%);
}
html[data-theme="midnight"] body {
  background:
    radial-gradient(1000px 500px at 10% 0%, rgba(192, 132, 252, 0.1), transparent 55%),
    radial-gradient(800px 400px at 100% 10%, rgba(88, 28, 135, 0.08), transparent 50%),
    linear-gradient(180deg, var(--bg0) 0%, var(--bg1) 100%);
}
button, input, textarea, select { font: inherit; }
a { color: var(--accent); }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- SVG Icon Helpers ---- */
svg.icon { display: inline-block; vertical-align: -0.125em; flex-shrink: 0; }

/* ---- Header ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-sm);
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  flex-shrink: 0;
  transition: var(--transition);
}
.brand-mark:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}
.brand-text { min-width: 0; }
.app-header .title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--text);
}
.e2ee-chip {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.app-header .sub {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 2px;
  word-break: break-all;
  line-height: 1.35;
  display: flex;
  align-items: center;
  gap: 4px;
}
.header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}
/* 登录阶段隐藏成员/分享按钮 */
body:not(.in-room) #btnUsers,
body:not(.in-room) #btnShare { display: none; }

/* ---- Theme Picker ---- */
.theme-picker {
  position: relative;
}
.theme-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 140px;
  padding: 6px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-solid);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  z-index: 100;
}
.theme-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.theme-option {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  padding: 8px 12px;
  font-size: 0.85rem;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.12s ease;
  line-height: 1.4;
}
.theme-option:hover {
  background: var(--accent-soft);
}
.theme-option.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.theme-option.active::after {
  content: ' ✓';
  float: right;
  color: var(--accent);
}

/* ---- Language Picker ---- */
.lang-picker {
  position: relative;
}
.lang-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 120px;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 4px 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  z-index: 100;
}
.lang-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.lang-option {
  display: block;
  width: 100%;
  border: none;
  background: none;
  padding: 8px 14px;
  font-size: 0.82rem;
  color: var(--fg);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease;
  line-height: 1.4;
}
.lang-option:hover {
  background: var(--accent-soft);
}
.lang-option.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.lang-option.active::after {
  content: ' ✓';
  float: right;
  color: var(--accent);
}
html[data-theme="dark"] .lang-dropdown,
html[data-theme="ocean"] .lang-dropdown,
html[data-theme="forest"] .lang-dropdown,
html[data-theme="sunset"] .lang-dropdown,
html[data-theme="midnight"] .lang-dropdown {
  background: var(--panel-solid);
  border-color: var(--border);
}

/* ---- Buttons ---- */
button.btn {
  border: 1px solid var(--border);
  background: var(--panel-solid);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  transition: var(--transition);
  box-shadow: var(--shadow-xs);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1;
  user-select: none;
}
html[data-theme="dark"] button.btn,
html[data-theme="ocean"] button.btn,
html[data-theme="forest"] button.btn,
html[data-theme="sunset"] button.btn,
html[data-theme="midnight"] button.btn {
  background: rgba(30, 41, 59, 0.85);
}
button.btn:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
  background: var(--accent-soft);
}
button.btn:active {
  transform: scale(0.97);
}
button.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button.btn.primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent) 0%, #6366f1 100%);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-glow);
}
button.btn.primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 6px 20px var(--accent-glow);
  transform: translateY(-1px);
}
button.btn.primary:active {
  transform: translateY(0) scale(0.97);
}
button.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
  filter: none !important;
  box-shadow: none !important;
}

/* 轻量级按钮（内联动作） */
button.btn.btn-ghost {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 4px 8px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
}
button.btn.btn-ghost:hover {
  color: var(--accent);
  background: var(--accent-soft);
  border: none;
  box-shadow: none;
}
button.btn.btn-ghost:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* 小号按钮 */
button.btn.btn-sm {
  padding: 6px 10px;
  font-size: 0.78rem;
  border-radius: 9px;
  gap: 5px;
}
button.btn.btn-sm svg { width: 14px; height: 14px; }

/* 纯文本按钮（安全说明等） */
.btn-text {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0 10px;
  text-align: left;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: var(--transition);
}
.btn-text:hover {
  color: var(--accent);
}

/* ---- App Container ---- */
#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 100%;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 0 16px 16px;
}

/* ---- Login Card ---- */
#loginPanel.login-card {
  max-width: 460px;
  margin: auto;
  width: 100%;
  padding: 24px 24px 28px;
  background: var(--panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  animation: loginFadeIn 0.4s ease;
}
@keyframes loginFadeIn {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.login-tagline {
  font-size: 1.1rem;
  color: var(--text);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.login-tagline strong {
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.login-header-icon {
  color: var(--accent);
  flex-shrink: 0;
}
.tagline-accent {
  color: var(--accent);
  font-weight: 600;
}

.toggle-arrow {
  display: inline-block;
  transition: transform var(--transition);
}
#btnSecurityToggle[aria-expanded="true"] .toggle-arrow {
  transform: rotate(90deg);
}

.login-security-panel {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.6;
  padding: 12px 14px;
  margin-bottom: 12px;
  border-radius: var(--radius);
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  animation: slideDown 0.25s ease;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Login Modules ---- */
.login-module {
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.login-module:first-of-type {
  border-top: none;
  padding-top: 0;
}
.login-module-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.login-step {
  width: 24px; height: 24px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}
.login-module-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
}

/* ---- Room Input ---- */
.room-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.room-input-wrap {
  flex: 1;
  min-width: 140px;
  position: relative;
  display: flex;
  align-items: center;
}
.room-input-wrap .input-icon {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
}
.room-input-wrap #roomInput {
  width: 100%;
  padding: 10px 42px 10px 36px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-solid);
  color: var(--text);
  outline: none;
  font-size: 0.9rem;
  transition: var(--transition);
}
.room-input-wrap #roomInput::placeholder { color: var(--muted); opacity: 0.6; }
.room-input-wrap #roomInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.room-input-wrap #roomInput.input-flash {
  animation: roomInputFlash 0.6s ease;
}
@keyframes roomInputFlash {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  40% { box-shadow: 0 0 0 3px var(--accent-soft); }
}
.room-apply-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px; height: 30px;
  border-radius: 8px;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  margin: 0;
  transition: var(--transition);
  z-index: 2;
}
.room-apply-btn:hover {
  background: var(--accent);
  color: #fff;
  transform: translateY(-50%) scale(1.08);
}
.room-apply-btn:active {
  transform: translateY(-50%) scale(0.95);
}
.text-muted-sm {
  font-size: 0.73rem;
  color: var(--muted);
  line-height: 1.45;
}
.room-row-hint { margin: 6px 0 0; }
.room-peek-line { margin: 6px 0 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.room-peek-line .text-muted-sm { flex: 1 1 auto; min-width: 0; }
.room-peek-line .btn { flex-shrink: 0; }
.preset-section-title {
  margin: 14px 0 8px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

/* ---- Preset Room Cards ---- */
.preset-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
  gap: 8px;
}
.preset-card {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-solid);
  cursor: pointer;
  outline: none;
  text-align: left;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.preset-card::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  background: linear-gradient(135deg, var(--accent-soft), transparent);
  transition: opacity var(--transition);
}
.preset-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
}
.preset-card:hover::before { opacity: 1; }
.preset-card:active { transform: translateY(0) scale(0.98); }
.preset-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.preset-card.active::before { opacity: 1; }
.preset-card .preset-card-name {
  position: relative;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
}
.preset-card .preset-card-meta {
  position: relative;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 3px;
  word-break: break-all;
}
.preset-card .preset-card-count {
  position: relative;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 5px;
}

/* ---- Password Module ---- */
.pass-lock-row {
  margin: 4px 0 8px;
}
.pass-lock-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: 0.84rem;
  line-height: 1.45;
  user-select: none;
}
.pass-lock-check input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.pass-lock-custom {
  flex-shrink: 0;
  width: 20px; height: 20px;
  border-radius: 6px;
  border: 2px solid var(--border);
  background: var(--panel-solid);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  margin-top: 2px;
}
.pass-lock-custom::after {
  content: '';
  width: 8px; height: 8px;
  border-radius: 3px;
  transform: scale(0);
  background: var(--accent);
  transition: transform 0.15s ease;
}
.pass-lock-check input:checked + .pass-lock-custom {
  border-color: var(--accent);
}
.pass-lock-check input:checked + .pass-lock-custom::after {
  transform: scale(1);
}
.pass-lock-check input:focus-visible + .pass-lock-custom {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.pass-lock-label {
  color: var(--text);
  cursor: pointer;
}

/* ---- Field Styles ---- */
.field-plain {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 8px 0;
}
.field-caption {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.field-plain input[type="text"],
.field-plain input[type="password"] {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-solid);
  color: var(--text);
  outline: none;
  transition: var(--transition);
}
.field-plain input::placeholder { color: var(--muted); opacity: 0.55; }
.field-plain input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.login-pass-hint {
  font-size: 0.73rem;
  color: var(--muted);
  margin: 6px 0 0;
  line-height: 1.45;
}

/* ---- Password Modal ---- */
.pass-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.2s ease;
}
.pass-modal[hidden] { display: none !important; }
.pass-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
html[data-theme="dark"] .pass-modal-backdrop,
html[data-theme="ocean"] .pass-modal-backdrop,
html[data-theme="forest"] .pass-modal-backdrop,
html[data-theme="sunset"] .pass-modal-backdrop,
html[data-theme="midnight"] .pass-modal-backdrop {
  background: rgba(0, 0, 0, 0.55);
}
.pass-modal-content {
  position: relative;
  width: min(360px, calc(100vw - 32px));
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  animation: modalSlideIn 0.25s ease;
}
.pass-modal-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.pass-modal-title {
  flex: 1;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}
.pass-modal-close {
  border: none;
  background: none;
  color: var(--muted);
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.pass-modal-close:hover {
  color: var(--text);
  background: var(--accent-soft);
}
.pass-modal-confirm {
  width: 100%;
  margin-top: 16px;
}
.pass-lock-row[hidden] { display: none; }
.field-plain[hidden] { display: none; }

/* ---- Nickname Row ---- */
.nick-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 6px;
}
.nick-field-grow { flex: 1; min-width: 200px; margin: 0; display: flex; flex-direction: column; gap: 5px; }
.abbr-help {
  cursor: help;
  text-decoration: none;
  font-weight: 700;
  color: var(--accent);
}
.nick-adjust-hint { margin-top: 6px; }

/* ---- Nickname Input with Avatar + Refresh ---- */
.nick-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.nick-input-wrap #nickInput {
  width: 100%;
  padding: 10px 42px 10px 48px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-solid);
  color: var(--text);
  outline: none;
  font-size: 0.9rem;
  transition: var(--transition);
}
.nick-input-wrap #nickInput::placeholder { color: var(--muted); opacity: 0.55; }
.nick-input-wrap #nickInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Avatar button inside input (left) */
button.nick-avatar-btn {
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px; height: 34px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  background: var(--accent-soft);
  cursor: pointer;
  padding: 0;
  margin: 0;
  transition: var(--transition);
  z-index: 2;
}
button.nick-avatar-btn:hover {
  border-color: var(--accent);
  transform: translateY(-50%) scale(1.08);
  box-shadow: var(--shadow-sm);
}

/* Refresh button inside input (right) */
button.nick-refresh-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 30px; height: 30px;
  border-radius: 8px;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  margin: 0;
  transition: var(--transition);
  z-index: 2;
}
button.nick-refresh-btn:hover {
  background: var(--accent);
  color: #fff;
  transform: translateY(-50%) scale(1.08);
}
button.nick-refresh-btn:active {
  transform: translateY(-50%) scale(0.95);
}

/* ---- Avatar Modal ---- */
.avatar-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.2s ease;
}
.avatar-modal[hidden] { display: none !important; }
@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.avatar-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
html[data-theme="dark"] .avatar-modal-backdrop,
html[data-theme="ocean"] .avatar-modal-backdrop,
html[data-theme="forest"] .avatar-modal-backdrop,
html[data-theme="sunset"] .avatar-modal-backdrop,
html[data-theme="midnight"] .avatar-modal-backdrop {
  background: rgba(0, 0, 0, 0.55);
}
html[data-theme="dark"] .theme-dropdown,
html[data-theme="ocean"] .theme-dropdown,
html[data-theme="forest"] .theme-dropdown,
html[data-theme="sunset"] .theme-dropdown,
html[data-theme="midnight"] .theme-dropdown {
  background: var(--panel-solid);
  border-color: var(--border);
}
.avatar-modal-content {
  position: relative;
  width: min(380px, calc(100vw - 32px));
  max-height: 70vh;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: 20px;
  overflow-y: auto;
  animation: modalSlideUp 0.25s ease;
}
@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.avatar-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.avatar-modal-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}
.avatar-modal-close {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.avatar-modal-close:hover {
  color: var(--text);
  background: var(--accent-soft);
}
.avatar-modal-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.avatar-modal-grid button {
  aspect-ratio: 1;
  width: 100%;
  border: 2px solid var(--border);
  background: var(--panel-solid);
  font-size: 1.4rem;
  cursor: pointer;
  border-radius: 12px;
  padding: 0;
  line-height: 1;
  transition: var(--transition);
}
.avatar-modal-grid button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: scale(1.1);
}
.avatar-modal-grid button.selected {
  outline: 2.5px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
  background: var(--accent-soft);
  transform: scale(1.1);
}

/* ---- Join CTA ---- */
.login-module-cta {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 4px;
}
.btn-join-main {
  width: 100%;
  padding: 11px 16px;
  font-size: 0.92rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.join-validation-hint { margin-top: 8px; min-height: 1.2em; font-size: 0.75rem; }

/* ---- Full-screen Loading Overlay ---- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--bg);
  animation: loadingFadeIn 0.3s ease;
}
.loading-overlay[hidden] { display: none !important; }
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.loading-text {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}
@keyframes loadingFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========================================================================
   CHAT PANEL
   ======================================================================== */
#chatPanel {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
  max-height: 100%;
  padding-top: 8px;
  animation: chatFadeIn 0.35s ease;
}
@keyframes chatFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.chat-e2ee-banner {
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  padding: 7px 12px;
  margin-bottom: 6px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--accent-soft);
  line-height: 1.4;
  opacity: 1;
  transition: opacity 0.6s ease, margin 0.6s ease, padding 0.6s ease, border-width 0.6s ease;
}
.chat-e2ee-banner.fade-out {
  opacity: 0;
  margin-bottom: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-width: 0;
}

/* ---- Messages Area ---- */
#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--shadow-md);
  scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}
#messages::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---- Message Bubbles ---- */
.msg { margin: 8px 0; display: flex; }
.msg.me { justify-content: flex-end; }
.msg.them { justify-content: flex-start; }
.msgRow {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: min(680px, 100%);
}
.msg.me .msgRow { flex-direction: row-reverse; }

.avatar {
  width: 38px; height: 38px;
  border-radius: 12px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  user-select: none;
  transition: var(--transition);
}
.msg.me .avatar {
  background: linear-gradient(145deg, var(--me-start), var(--me-end));
}
.msg .avatar:hover { transform: scale(1.08); }

.bubble {
  flex: 1;
  min-width: 0;
  padding: 10px 13px 11px;
  border-radius: 16px;
  border: 1px solid transparent;
  word-break: break-word;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition);
  animation: bubbleIn 0.2s ease;
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.bubble:hover { box-shadow: var(--shadow-sm); }
.msg.me .bubble {
  background: linear-gradient(145deg, var(--me-start) 0%, var(--me-end) 100%);
  border-color: rgba(99, 102, 241, 0.2);
  border-bottom-right-radius: 4px;
}
.msg.them .bubble {
  background: var(--them);
  border-color: var(--them-border);
  border-bottom-left-radius: 4px;
}
.msg.system {
  justify-content: center;
  animation: systemFadeIn 0.25s ease;
}
@keyframes systemFadeIn {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg.system .bubble {
  background: var(--system-bg);
  font-size: 0.76rem;
  color: var(--muted);
  white-space: pre-wrap;
  max-width: 88%;
  text-align: center;
  border-radius: 999px;
  padding: 7px 16px;
  box-shadow: none;
  border-color: transparent;
}
.msg.system .bubble:hover { box-shadow: none; }

.meta {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
  letter-spacing: 0.02em;
}
.meta.sig-ok {
  color: #22c55e;
}
.meta.sig-fail {
  color: #ef4444;
}
.payload-text {
  white-space: pre-wrap;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text);
}
.payload-text .chat-link {
  color: #3b82f6;
  text-decoration: none;
  word-break: break-all;
}
.payload-text .chat-link:hover {
  text-decoration: underline;
  color: #60a5fa;
}
.msg.me .payload-text { color: var(--text); }
.msg.me .payload-text .chat-link {
  color: #93c5fd;
}
.msg.me .payload-text .chat-link:hover {
  color: #bfdbfe;
}

.payload-img {
  max-width: 100%;
  max-height: 280px;
  border-radius: 10px;
  display: block;
  margin-top: 5px;
  box-shadow: var(--shadow-sm);
  cursor: zoom-in;
  transition: var(--transition);
  object-fit: contain;
}
.payload-img:hover {
  box-shadow: var(--shadow-md);
  transform: scale(1.01);
}

/* ---- Image Lightbox ---- */
.img-lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.img-lightbox.open {
  opacity: 1;
  pointer-events: auto;
}
.img-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.img-lightbox-body {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 92vw;
  max-height: 88vh;
  animation: lbZoomIn 0.25s ease;
}
@keyframes lbZoomIn {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.img-lightbox-body img {
  max-width: 92vw;
  max-height: 88vh;
  object-fit: contain;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  user-select: none;
}
.img-lightbox-close {
  position: absolute;
  top: -12px; right: -12px;
  width: 40px; height: 40px;
  border-radius: 999px;
  border: none;
  background: var(--panel-solid);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
  z-index: 5;
}
.img-lightbox-close:hover {
  background: var(--accent);
  color: #fff;
  transform: scale(1.1);
}
.payload-file { margin-top: 6px; }
.payload-file a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--accent-soft);
  transition: var(--transition);
}
.payload-file a:hover {
  background: var(--accent-soft);
  filter: brightness(1.1);
}

/* ---- Composer ---- */
#composerWrap {
  position: relative;
  flex-shrink: 0;
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: linear-gradient(180deg, transparent 0%, var(--bg1) 25%);
  margin-top: 4px;
}
/* ---- 手机端虚拟键盘避让 ---- */
#composerWrap.keyboard-up {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg1);
}
#chatPanel.keyboard-up {
  /* composer 已 fixed 脱离文档流，留出等高占位避免消息被遮挡 */
  padding-bottom: 80px;
}
/* ---- 离线时 composer 禁用遮罩 ---- */
.composer-offline-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  inset: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg1) 80%, transparent);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  border-radius: inherit;
  user-select: none;
  cursor: not-allowed;
  animation: overlayFadeIn 0.25s ease;
}
.composer-offline-overlay[hidden] {
  display: none;
}
@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
#composerTools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
#composerTools .btn {
  padding: 6px 10px;
  font-size: 0.78rem;
  border-radius: 9px;
  box-shadow: none;
}
.btn-destroy {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-destroy:hover {
  background: rgba(239, 68, 68, 0.12);
  border-color: #ef4444;
}

.composer-hint {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.7;
  white-space: nowrap;
}

#composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 2px 2px 0;
}
#pendingImgWrap {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  margin-bottom: 2px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--border);
  background: var(--panel-solid);
}
#pendingImgWrap[hidden] {
  display: none;
}
#pendingImgThumb {
  display: block;
  max-width: 120px;
  max-height: 90px;
  object-fit: contain;
}
#btnRemovePendingImg {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.15s;
}
#btnRemovePendingImg:hover {
  background: rgba(239,68,68,0.85);
}
#msgInput {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  resize: vertical;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-solid);
  color: var(--text);
  outline: none;
  line-height: 1.45;
  transition: var(--transition);
}
#msgInput::placeholder { color: var(--muted); opacity: 0.5; }
#msgInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#composer .btn.primary {
  padding: 11px 16px;
  border-radius: 12px;
  align-self: stretch;
  min-height: 44px;
  gap: 4px;
}

/* ---- Emoji Panel (Tab-based) ---- */
#emojiPanel {
  display: none;
  position: absolute;
  left: 0; right: 0;
  bottom: 100%;
  width: min(420px, calc(100vw - 32px));
  height: 320px;
  z-index: 50;
  margin-bottom: 8px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-xl);
  animation: panelSlideUp 0.2s ease;
  overflow: hidden;
}
#emojiPanel.open { display: flex; flex-direction: column; }
@keyframes panelSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Tab bar */
.emoji-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 0;
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  scrollbar-width: thin;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  position: relative;
}
.emoji-tabs::-webkit-scrollbar { height: 3px; }
.emoji-tabs::-webkit-scrollbar-track { background: transparent; }
.emoji-tabs::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}
.emoji-tabs::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* 选项卡栏左右渐变遮罩（滚动提示） */
.emoji-tabs-fade-left,
.emoji-tabs-fade-right {
  position: absolute;
  top: 0;
  height: 46px;
  width: 28px;
  z-index: 2;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.emoji-tabs-fade-left {
  left: 0;
  background: linear-gradient(to right, var(--panel-solid), transparent);
  border-radius: var(--radius-lg) 0 0 0;
}
.emoji-tabs-fade-right {
  right: 0;
  background: linear-gradient(to left, var(--panel-solid), transparent);
  border-radius: 0 var(--radius-lg) 0 0;
}
.emoji-tab {
  flex-shrink: 0;
  scroll-snap-align: start;
  border: none;
  background: transparent;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 10px 10px 0 0;
  transition: background 0.15s ease, transform 0.15s ease;
  position: relative;
  color: var(--text);
}
.emoji-tab::after {
  content: '';
  position: absolute;
  bottom: 0; left: 20%; right: 20%;
  height: 2.5px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.emoji-tab:hover {
  background: var(--accent-soft);
  transform: scale(1.1);
}
.emoji-tab.active {
  background: var(--accent-soft);
}
.emoji-tab.active::after {
  transform: scaleX(1);
}

/* Content area */
.emoji-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 14px;
  min-height: 0;
}
.emoji-content::-webkit-scrollbar { width: 4px; }
.emoji-content::-webkit-scrollbar-track { background: transparent; }
.emoji-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}
.emoji-content::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* Tab body (one per category) */
.emoji-tab-body {
  display: none;
  animation: emojiTabFadeIn 0.2s ease;
}
.emoji-tab-body.active {
  display: block;
}
@keyframes emojiTabFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Emoji grid */
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 4px;
}

/* Emoji cell */
#emojiPanel button.emoji-cell {
  border: none;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  padding: 6px;
  border-radius: 10px;
  transition: background 0.12s ease, transform 0.12s ease;
  line-height: 1;
  position: relative;
}
#emojiPanel button.emoji-cell:hover {
  background: var(--accent-soft);
  transform: scale(1.18);
  z-index: 2;
}
#emojiPanel button.emoji-cell:active {
  transform: scale(0.88);
  background: var(--accent-glow);
}

/* Click pulse animation */
#emojiPanel button.emoji-cell::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--accent-soft);
  transform: scale(0);
  opacity: 0;
  pointer-events: none;
}
@keyframes emojiPulse {
  0% { transform: scale(0.5); opacity: 0.6; }
  100% { transform: scale(2); opacity: 0; }
}
#emojiPanel button.emoji-cell:active::before {
  animation: emojiPulse 0.35s ease-out;
}

/* Hover preview bubble */
.emoji-preview {
  position: absolute;
  bottom: 8px;
  right: 12px;
  font-size: 2.8rem;
  line-height: 1;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 10;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.15));
}
.emoji-preview.show {
  opacity: 1;
  transform: scale(1);
}

/* ---- Users Drawer ---- */
#usersDrawer {
  position: fixed;
  right: 14px;
  top: 66px;
  width: min(300px, calc(100vw - 28px));
  max-height: 50vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 16px;
  display: none;
  z-index: 30;
  box-shadow: var(--shadow-xl);
  animation: panelSlideUp 0.2s ease;
}
#usersDrawer::-webkit-scrollbar { width: 4px; }
#usersDrawer::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}
.users-header {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.users-header strong {
  color: var(--accent);
  font-weight: 700;
}
.icon-valign {
  vertical-align: -2px;
}
.icon-valign-3 {
  vertical-align: -3px;
}
.icon-mr-xs {
  margin-right: 4px;
}
.users-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 8px;
  border-radius: 10px;
  transition: background 0.15s ease;
}
.users-item + .users-item {
  border-top: 1px solid var(--border);
}
.users-item:hover {
  background: var(--accent-soft);
}
.users-item-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  line-height: 1;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
}
.users-item-info {
  flex: 1;
  min-width: 0;
}
.users-item-nick {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.3;
}
.users-item-sid {
  font-size: 0.68rem;
  color: var(--muted);
  word-break: break-all;
  line-height: 1.4;
  margin-top: 2px;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", "Consolas", monospace;
  opacity: 0.7;
}
.users-item-fp {
  font-size: 0.62rem;
  color: var(--accent);
  word-break: break-all;
  line-height: 1.4;
  margin-top: 2px;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", "Consolas", monospace;
  opacity: 0.85;
  letter-spacing: 0.02em;
}

/* ---- Status Pill ---- */
#statusPill {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
  background: var(--panel-solid);
  letter-spacing: 0.02em;
}
#statusPill.ok {
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.35);
  background: var(--success-soft);
}
#statusPill.bad {
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.2);
  background: rgba(220, 38, 38, 0.06);
}
#statusPill.neutral,
.status-pill.neutral {
  color: var(--muted);
  border-color: var(--border);
  background: var(--panel-solid);
}
.status-pill--hidden { display: none !important; }

/* ---- Toast (居中轻提示) ---- */
.toast-bar {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: var(--radius);
  border: none;
  background: rgba(0,0,0,.62);
  color: #fff;
  font-size: 0.82rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  z-index: 9999;
  pointer-events: none;
  white-space: nowrap;
  animation: toastFadeIn .22s ease;
}
@keyframes toastFadeIn {
  from { opacity: 0; transform: translate(-50%,-50%) scale(.92); }
  to   { opacity: 1; transform: translate(-50%,-50%) scale(1); }
}
.toast-bar.toast-out {
  animation: toastFadeOut .2s ease forwards;
}
@keyframes toastFadeOut {
  from { opacity: 1; transform: translate(-50%,-50%) scale(1); }
  to   { opacity: 0; transform: translate(-50%,-50%) scale(.92); }
}
.toast-bar[hidden] { display: none !important; }
.toast-close { display: none; }

/* ---- Legacy compat (used by JS) ---- */
.field { display: flex; flex-direction: column; gap: 8px; margin: 18px 0 14px; }
.field label { font-size: 0.75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-solid);
  color: var(--text);
  outline: none;
  transition: var(--transition);
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- Responsive ---- */
@media (max-width: 720px) {
  .app-header .sub { display: none; }
  #app { padding: 0 10px 12px; }
  .brand-mark { width: 36px; height: 36px; }
  .brand-mark svg { width: 18px; height: 18px; }
  #loginPanel.login-card { padding: 18px 16px 22px; }
  .preset-cards { grid-template-columns: repeat(auto-fill, minmax(115px, 1fr)); }
  .header-actions .btn-label { display: none; }
  .composer-hint { display: none; }
  .msgRow { max-width: 92%; }
  .avatar { width: 34px; height: 34px; font-size: 18px; }
  #emojiPanel { width: calc(100vw - 20px); height: 300px; }
  .emoji-tab { padding: 7px 8px; font-size: 1.15rem; }
  .emoji-grid { grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 3px; }
  #emojiPanel button.emoji-cell { font-size: 20px; padding: 5px; }
}

@media (max-width: 480px) {
  #loginPanel.login-card { border-radius: var(--radius-lg); }
  .login-module { padding: 12px 0; }
  .avatar-modal-grid { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .avatar-modal-content { padding: 16px; }
  #emojiPanel { height: 280px; }
  .emoji-grid { grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 2px; }
  #emojiPanel button.emoji-cell { font-size: 18px; padding: 4px; border-radius: 8px; }
  .emoji-preview { font-size: 2.2rem; bottom: 4px; right: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
