@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  --bg: #f8f9fc;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --border: #e8ecf3;
  --border-light: #f0f2f7;
  --text: #1a1d29;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --primary: #6c5ce7;
  --primary-light: #a29bfe;
  --primary-dark: #5a4bd1;
  --accent: #fd79a8;
  --green: #00b894;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --sidebar-w: 280px;
}
[data-theme="dark"] {
  --bg: #13151f;
  --surface: #1e2030;
  --surface-2: #282a3a;
  --border: #333550;
  --border-light: #2a2c40;
  --text: #e4e6f0;
  --text-2: #9ca0b8;
  --text-3: #6b6f88;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.25), 0 1px 2px rgba(0,0,0,.35);
  --shadow-md: 0 4px 16px rgba(0,0,0,.35), 0 2px 8px rgba(0,0,0,.25);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.45);
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ===== Auth Pages ===== */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #f8f9fc 0%, #eef1f8 50%, #f0eeff 100%);
}

/* Decorative Background */
.bg-decoration {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
.bg-decoration .circle {
  position: absolute;
  border-radius: 50%;
  opacity: .35;
}
.bg-decoration .c1 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, var(--primary-light), transparent 70%);
  top: -150px; right: -100px;
  animation: floatA 12s ease-in-out infinite;
}
.bg-decoration .c2 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, var(--accent), transparent 70%);
  bottom: -100px; left: -80px;
  animation: floatB 15s ease-in-out infinite;
}
.bg-decoration .c3 {
  width: 250px; height: 250px;
  background: radial-gradient(circle, #74b9ff, transparent 70%);
  top: 40%; left: 5%;
  animation: floatA 10s ease-in-out infinite reverse;
}
.bg-decoration .c4 {
  width: 200px; height: 200px;
  background: radial-gradient(circle, var(--green), transparent 70%);
  bottom: 20%; right: 10%;
  animation: floatB 13s ease-in-out infinite;
}
.bg-decoration .dots {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--primary) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: .05;
}

@keyframes floatA {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(30px, -30px) scale(1.05); }
}
@keyframes floatB {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(-25px, 25px) scale(1.08); }
}

/* Auth Card */
.auth-card {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 44px 40px 36px;
  width: 420px;
  max-width: 92vw;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(108,92,231,.08);
  animation: cardIn .5s ease;
}
@keyframes cardIn {
  from { opacity:0; transform:translateY(24px) scale(.97); }
  to   { opacity:1; transform:translateY(0) scale(1); }
}
.auth-header {
  text-align: center;
  margin-bottom: 28px;
}
.auth-logo {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  box-shadow: 0 8px 24px rgba(108,92,231,.25);
}
.auth-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.auth-header p {
  color: var(--text-2);
  font-size: 14px;
}

/* Alert */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 18px;
  border: 1px solid;
}
.alert-error {
  background: #fff0f0;
  color: #e74c3c;
  border-color: #ffd5d5;
}

/* Form */
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.input-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.input-icon {
  position: absolute;
  left: 14px;
  font-size: 16px;
  opacity: .6;
  pointer-events: none;
}
.input-wrap input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  outline: none;
  transition: border-color .25s, box-shadow .25s;
}
.input-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(108,92,231,.1);
}
.input-wrap input::placeholder { color: var(--text-3); }

/* Button */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 13px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 4px 14px rgba(108,92,231,.3);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(108,92,231,.35);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    padding: 0 16px;
    border: 1px solid var(--border-color, #d9d9d9);
    border-radius: 8px;
    background: var(--bg-tertiary, #f5f5f5);
    color: var(--text, #333);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn-secondary:hover { background: var(--bg-hover, #e8e8e8); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-footer {
  text-align: center;
  margin-top: 22px;
  font-size: 14px;
  color: var(--text-2);
}
.auth-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}
.auth-footer a:hover { text-decoration: underline; }

/* ===== Chat Layout ===== */
.app-container {
  display: flex;
  height: 100vh;
  background: var(--bg);
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10;
  transition: transform .3s ease;
}
.sidebar-brand {
  padding: 28px 24px 20px;
  text-align: center;
  position: relative;
}
.sidebar-brand::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 24px;
  right: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.brand-icon {
  width: 52px; height: 52px;
  margin: 0 auto 12px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 6px 20px rgba(108,92,231,.2);
}
.sidebar-brand h2 {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand-subtitle {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

.online-section {
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 8px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.online-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 24px 12px;
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
}
.online-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}
/* Sidebar footer */
.sidebar-announcement {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
  background: var(--surface-2);
}
.sidebar-announcement p { margin: 4px 0; }
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
}
.current-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
.current-user-info {
  display: flex;
  flex-direction: column;
}
.current-user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.current-user-status {
  font-size: 11px;
  color: var(--green);
  font-weight: 500;
}
.logout-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  text-decoration: none;
  transition: background .2s;
  opacity: .5;
}
.logout-btn:hover {
  background: var(--border);
  opacity: 1;
}
.theme-toggle {
  width: 36px; height: 36px;
  border: none; border-radius: var(--radius-sm);
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; cursor: pointer;
  transition: background .2s;
  opacity: .5;
}
.theme-toggle:hover { background: var(--border); opacity: 1; }

/* ---- Main Content ---- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
}
.chat-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 24px;
  right: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-2);
  padding: 4px;
  border-radius: var(--radius-sm);
}
.menu-toggle:hover { background: var(--surface-2); color: var(--text); }
.chat-header-info h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.chat-header-meta {
  font-size: 12px;
  color: var(--text-3);
}
.chat-header-actions {
  margin-left: auto;
  position: relative;
}
.status-indicator {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}
.header-mute-btn {
  width: 34px; height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, transform .2s;
  line-height: 1;
  margin-right: 6px;
}
.header-mute-btn:hover {
  background: var(--border);
  transform: scale(1.1);
}
.header-mute-btn.muted {
  opacity: .55;
}

/* ---- Header avatar ---- */
.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.header-avatar {
  flex-shrink: 0;
}
.header-avatar img,
.header-avatar div[style] {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}
.header-info-text {
  min-width: 0;
}
.header-info-text h3 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Mention popup ---- */
.avatar-mention-popup {
  position: fixed;
  z-index: 9999;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  display: none;
}
.avatar-mention-popup .mention-popup-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
  width: 100%;
}
.avatar-mention-popup .mention-popup-btn:hover {
  background: var(--surface-2);
}
.header-profile-btn {
  width: 34px; height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, transform .2s;
  line-height: 1;
  margin-right: 6px;
}
.header-profile-btn:hover {
  background: var(--border);
  transform: scale(1.1);
}

/* ---- Messages ---- */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: 
    radial-gradient(ellipse at 20% 50%, rgba(108,92,231,.03) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(253,121,168,.03) 0%, transparent 50%),
    var(--bg);
}
.messages-container::-webkit-scrollbar { width: 5px; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }

.loading-msg {
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  padding: 40px 0;
}

/* Message */
.msg {
  display: flex;
  gap: 10px;
  max-width: 80%;
  animation: msgIn .3s ease;
}
@keyframes msgIn {
  from { opacity:0; transform:translateY(8px); }
  to   { opacity:1; transform:translateY(0); }
}
.msg.own {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.msg-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  margin-top: 2px;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.msg-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.msg.own .msg-body { align-items: flex-end; }
.msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
  padding: 0 4px;
}
.msg.own .msg-head { flex-direction: row-reverse; }
.msg-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}
.msg-time {
  font-size: 11px;
  color: var(--text-3);
}
.msg-bubble {
  padding: 10px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
}
.msg:not(.own) .msg-bubble {
  border-bottom-left-radius: 4px;
}
.msg.own .msg-bubble {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border: none;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 14px rgba(108,92,231,.2);
}

/* System message */
.system-msg {
  text-align: center;
  color: var(--text-3);
  font-size: 12px;
  padding: 8px 0;
  font-weight: 500;
  position: relative;
}
.system-msg::before,
.system-msg::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 24px;
  height: 1px;
  background: var(--border);
}
.system-msg::before { left: calc(50% + 60px); }
.system-msg::after { right: calc(50% + 60px); }

/* ---- Input Area ---- */
.input-area {
  padding: 16px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  position: relative;
}
.input-area::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 24px;
  right: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.input-toolbar {
  display: flex;
  gap: 4px;
  padding: 0 0 6px 0;
}
.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  padding: 6px 6px 6px 14px;
  border: 2px solid var(--border);
  transition: border-color .25s, box-shadow .25s;
}
.input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(108,92,231,.08);
}
.input-wrapper textarea {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  outline: none;
  line-height: 1.5;
  padding: 8px 0;
  min-height: 24px;
  max-height: 96px;
}
.input-wrapper textarea::placeholder { color: var(--text-3); }
.input-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.char-count {
  font-size: 11px;
  color: var(--text-3);
  min-width: 20px;
  text-align: center;
  font-weight: 500;
}
.send-btn {
  width: 40px; height: 40px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s, box-shadow .2s;
  flex-shrink: 0;
}
.send-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(108,92,231,.3);
}
.send-btn:active { transform: translateY(0); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---- Tool Buttons ---- */
.tool-btn {
  width: 36px; height: 36px;
  border: none; border-radius: var(--radius-sm);
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .2s;
  line-height: 1;
}
.tool-btn:hover {
  background: var(--border);
}
.tool-btn.recording {
  background: #e74c3c;
  color: #fff;
  animation: pulse-red 1s ease infinite;
}
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,.4); }
  50% { box-shadow: 0 0 0 8px rgba(231,76,60,0); }
}

/* ---- Voice Recording UI ---- */
.voice-recording {
  display: none;
  align-items: center;
  gap: 8px;
  flex: 1;
  padding: 8px 12px;
  background: rgba(231,76,60,.08);
  border-radius: var(--radius-sm);
}
.voice-rec-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #e74c3c;
  animation: blink 1s step-end infinite;
}
@keyframes blink {
  50% { opacity: 0; }
}
.voice-rec-timer {
  font-size: 14px;
  font-weight: 700;
  color: #e74c3c;
  min-width: 32px;
  font-variant-numeric: tabular-nums;
}
.voice-rec-label {
  font-size: 13px;
  color: var(--text-2);
  flex: 1;
}
.voice-rec-cancel {
  width: 24px; height: 24px;
  border: none; border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.voice-rec-cancel:hover {
  background: var(--border);
}

/* ---- Emoji Picker ---- */
.emoji-picker {
  position: absolute;
  bottom: 80px;
  left: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  display: none;
  z-index: 30;
  max-width: 340px;
}
.emoji-tabs {
  display: flex;
  gap: 4px;
  padding: 0 4px 8px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.emoji-tab {
  flex-shrink: 0;
  width: 34px; height: 34px;
  border: none; border-radius: var(--radius-sm);
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; cursor: pointer;
  transition: background .15s;
}
.emoji-tab:hover { background: var(--surface-2); }
.emoji-tab.active { background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--primary); }
.emoji-tab img {
  width: 24px; height: 24px;
  border-radius: 4px;
  object-fit: cover;
}
.emoji-picker.open { display: block; animation: pickerIn .2s ease; }
@keyframes pickerIn {
  from { opacity:0; transform:translateY(8px) scale(.96); }
  to   { opacity:1; transform:translateY(0) scale(1); }
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}
.emoji-grid::-webkit-scrollbar { width: 4px; }
.emoji-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.emoji-item {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
}
.emoji-item:hover { background: var(--surface-2); }

/* ---- Image Preview ---- */
.image-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.image-preview img {
  max-height: 80px;
  max-width: 140px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  box-shadow: var(--shadow-sm);
}
.preview-close {
  width: 28px; height: 28px;
  border: none; border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.preview-close:hover { background: var(--border); }

/* ---- Image in message ---- */
.msg-bubble { padding: 10px 16px; }
.msg.own .msg-bubble { padding: 10px 16px; }
.msg-text { line-height: 1.55; }
.msg-image { margin-top: 6px; }
.msg-image img {
  max-width: 220px;
  max-height: 220px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: block;
  transition: opacity .2s;
  box-shadow: var(--shadow-sm);
}
.msg-image img:hover { opacity: .85; }
.msg.own .msg-image img {
  box-shadow: 0 2px 10px rgba(108,92,231,.25);
}
.msg-video { margin-top: 6px; }
.msg-video video {
  max-width: 320px;
  max-height: 320px;
  border-radius: var(--radius-sm);
  display: block;
  box-shadow: var(--shadow-sm);
}

/* ---- Voice message ---- */
.msg-voice {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 140px;
  max-width: 200px;
  margin-top: 2px;
}
.voice-play-btn {
  width: 32px; height: 32px;
  border: none; border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .2s, transform .1s;
}
.voice-play-btn:hover { background: var(--primary-dark); transform: scale(1.05); }
.voice-play-btn:active { transform: scale(.95); }
.msg.own .voice-play-btn { background: rgba(255,255,255,.25); }
.msg.own .voice-play-btn:hover { background: rgba(255,255,255,.35); }
.voice-wave {
  flex: 1;
  height: 24px;
  background: var(--border);
  border-radius: 4px;
  opacity: .25;
}
.voice-duration {
  font-size: 12px;
  color: var(--text-2);
  min-width: 32px;
  font-variant-numeric: tabular-nums;
}

/* ---- Recalled message ---- */
.msg-recalled {
  font-size: 13px;
  color: var(--text-3);
  font-style: italic;
  padding: 4px 0;
}

/* ---- Avatar recall popup ---- */
.avatar-recall-popup {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  display: none;
  z-index: 999;
  box-shadow: var(--shadow-lg);
  font-size: 12px;
  min-width: 140px;
  max-height: 240px;
  overflow-y: auto;
}
.recall-popup-preview {
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  word-break: break-all;
}
.recall-popup-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.recall-popup-btn {
  color: #e74c3c;
  cursor: pointer;
  border-bottom: 1px dashed #e74c3c;
  user-select: none;
  font-size: 13px;
}
.recall-popup-btn:hover {
  color: #c0392b;
}
.recall-popup-timer {
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* ---- Profile recall section ---- */
.profile-recall-section {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.profile-recall-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}
.profile-recall-empty {
  font-size: 13px;
  color: var(--text-3);
  padding: 8px 0;
}
.profile-recall-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  margin-bottom: 4px;
  font-size: 13px;
}
.profile-recall-item.expired {
  opacity: 0.5;
}
.profile-recall-text {
  flex: 1;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.profile-recall-timer {
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  min-width: 40px;
  text-align: right;
}
.profile-recall-action {
  color: #e74c3c;
  cursor: pointer;
  border-bottom: 1px dashed #e74c3c;
  user-select: none;
  font-size: 12px;
}
.profile-recall-action:hover {
  color: #c0392b;
}

/* ---- Admin badge ---- */
.admin-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: linear-gradient(135deg, #6c5ce7, #5a4bd1);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  margin-left: 6px;
  vertical-align: middle;
  line-height: 1.4;
}
.admin-badge-sm {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: linear-gradient(135deg, #6c5ce7, #5a4bd1);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  vertical-align: middle;
  line-height: 1.4;
}
.chart-header-total {
  font-size: 12px;
  color: var(--text-3);
  margin-left: 4px;
}

/* ---- @mention button in profile ---- */
.profile-mention-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  user-select: none;
  transition: background .15s;
}
.profile-mention-btn:hover {
  background: var(--surface-3);
}
/* ---- Sidebar Search ---- */
.sidebar-search {
  padding: 8px 16px 12px;
}
.search-wrap {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 0 4px 0 12px;
  border: 2px solid transparent;
  transition: border-color .25s, box-shadow .25s;
}
.search-wrap:focus-within {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 4px rgba(108,92,231,.15);
}
.search-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 0;
  font-size: 13px;
  font-family: var(--font);
  color: var(--text);
  outline: none;
}
.search-wrap input::placeholder { color: var(--text-3); }
.search-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: background .2s, transform .1s;
  line-height: 1.4;
}
.search-btn:hover { background: #5a4bd1; }
.search-btn:active { transform: scale(.96); }

/* ---- Conversation List ---- */
.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.conv-section { margin-bottom: 4px; }
.conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--surface-2); }
.conv-item.active .conv-name { color: var(--primary); font-weight: 700; }

.unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  border-radius: 10px;
  background: #e74c3c;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  box-shadow: 0 2px 6px rgba(231,76,60,.4);
  z-index: 2;
  line-height: 1;
  pointer-events: none;
}
.unread-badge.muted {
  background: #9ca3af;
  box-shadow: none;
}

.conv-avatar {
  position: relative;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}
.conv-info { flex: 1; min-width: 0; }
.conv-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-preview {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

/* ---- Modals ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity .3s, visibility .3s;
}
.modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 92vw;
  animation: modalIn .3s ease;
}
.modal-box.sm { width: 400px; }
.modal-box.md { width: 520px; }
@keyframes modalIn {
  from { opacity:0; transform:translateY(16px) scale(.97); }
  to   { opacity:1; transform:translateY(0) scale(1); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; color: var(--text); }
.modal-close {
  width: 30px; height: 30px;
  border: none; border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.modal-close:hover { background: var(--border); }
.modal-body { padding: 18px 20px 20px; }
.modal-empty {
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
  padding: 20px 0;
}
.announcement-box { width: 520px; max-height: 80vh; display: flex; flex-direction: column; }
.announcement-body {
  padding: 18px 20px;
  overflow-y: auto;
  line-height: 1.6;
  font-size: 14px;
  color: var(--text);
  max-height: 50vh;
}
.announcement-body p { margin: 6px 0; }
.announcement-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
}
.announcement-footer .btn-sm { padding: 8px 16px; font-size: 13px; }

/* ---- Color Picker ---- */
.color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.color-swatch {
  width: 30px; height: 30px;
  border-radius: 8px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color .2s, transform .2s;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active { border-color: var(--text); transform: scale(1.15); }

/* ---- Group Settings ---- */
#gsBody .form-group { margin-bottom: 12px; }
#gsBody .form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}
#gsBody .form-group input[type="text"],
#gsBody .form-group input[type="file"] {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  outline: none;
}
#gsBody .form-group input:focus { border-color: var(--primary); }
.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500 !important;
}
.checkbox-label input { width: auto !important; }

/* ---- Request Items ---- */
.request-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  margin-bottom: 6px;
}
.request-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}
.req-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}
.request-user small { color: var(--text-3); font-size: 12px; }
.request-actions { display: flex; gap: 4px; }
.req-btn {
  width: 28px; height: 28px;
  border: none; border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.req-btn.approve { background: #d4edda; color: #155724; }
.req-btn.approve:hover { background: #b8dfc6; }
.req-btn.reject { background: #f8d7da; color: #721c24; }
.req-btn.reject:hover { background: #f1c0c0; }

/* ---- Form inside modals ---- */
#profileForm .form-group,
#groupForm .form-group {
  margin-bottom: 14px;
}
#profileForm .form-group label,
#groupForm .form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}
#profileForm input[type="text"],
#profileForm textarea,
#groupForm input {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .25s;
}
#profileForm input:focus,
#profileForm textarea:focus,
#groupForm input:focus {
  border-color: var(--primary);
}
#profileForm textarea {
  resize: vertical;
  min-height: 60px;
  line-height: 1.5;
}
#profileForm input[disabled] { opacity: .7; }
.hint {
  font-size: 12px;
  color: var(--text-3);
  margin: -6px 0 14px;
}

/* ---- Responsive ---- */
/* ===== Friend Request Bar ===== */
.friend-request-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  margin: 0 8px 8px;
  background: linear-gradient(135deg, var(--primary-light), var(--accent));
  color: #fff;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: opacity .2s;
}
.friend-request-bar:hover {
  opacity: .9;
}
.req-badge {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(255,255,255,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

/* ===== Search Result Cards ===== */
.search-section { margin-bottom: 4px; }
.search-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 8px 4px 6px;
}
.search-user-card,
.search-group-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  transition: background .2s;
  cursor: default;
}
.search-user-card:hover,
.search-group-card:hover {
  background: var(--border);
}
.search-group-card { cursor: pointer; }
.search-card-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.search-card-avatar img { width: 100%; height: 100%; object-fit: cover; }
.search-card-info {
  flex: 1;
  min-width: 0;
}
.search-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.search-card-code {
  font-size: 12px;
  color: var(--text-3);
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.search-card-bio {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.search-add-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  white-space: nowrap;
  flex-shrink: 0;
}
.search-add-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(108,92,231,.3);
}
.search-card-self {
  font-size: 12px;
  color: var(--text-3);
  background: var(--border);
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 500;
}
.search-empty {
  text-align: center;
  padding: 24px 0;
}
.search-empty-icon {
  font-size: 32px;
  display: block;
  margin-bottom: 8px;
  opacity: .5;
}
.search-empty p {
  font-size: 14px;
  color: var(--text-3);
}

/* ===== Friend Picker (create group) ===== */
.friend-picker {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px;
}
.friend-picker::-webkit-scrollbar { width: 4px; }
.friend-picker::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.friend-pick-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
  font-size: 14px;
}
.friend-pick-item:hover {
  background: var(--surface-2);
}
.friend-pick-item input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--primary);
}
.pick-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}

/* ===== Profile Card Improvements ===== */
.profile-card {
  text-align: center;
}
.profile-avatar-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}
.profile-avatar {
  width: 80px; height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
  border: 3px solid var(--surface);
  outline: 2px solid var(--border);
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}
.profile-code {
  font-size: 14px;
  color: var(--text-3);
  margin: 2px 0 8px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  background: var(--surface-2);
  display: inline-block;
  padding: 2px 12px;
  border-radius: 12px;
}
.profile-bio {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
  max-width: 280px;
  margin: 4px auto 12px;
  padding: 8px 16px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.profile-bio-empty {
  color: var(--text-3);
  font-style: italic;
  background: transparent;
}
.profile-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  color: var(--text-3);
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.profile-add-btn {
  width: 100%;
  margin-top: 12px;
}

/* ===== Header Online Popover ===== */
.header-online {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  position: relative;
}
.header-online-list {
  display: none !important;
}
.online-dot-sm {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}

/* ===== Group create button ===== */
.conv-add-btn {
  padding: 4px 10px;
  border: none;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.conv-add-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(108,92,231,.3);
}
.btn-sm {
  display:inline-flex;align-items:center;gap:4px;
  padding:4px 10px;border:none;border-radius:6px;
  font-size:12px;cursor:pointer;font-family:var(--font);
  transition:opacity .2s;
}
.btn-sm-ban { background:rgba(231,76,60,.1);color:#e74c3c; }
.btn-sm-ban:hover { background:rgba(231,76,60,.2); }
.group-gear {
  margin-left: auto;
  font-size: 14px;
  opacity: 0;
  transition: opacity .2s;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  flex-shrink: 0;
  line-height: 1;
}
.conv-item:hover .group-gear {
  opacity: .6;
}
.group-gear:hover {
  opacity: 1 !important;
  background: var(--border);
}
.conv-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  padding: 8px 12px 4px;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.conv-section-title span {
  text-transform: uppercase;
  letter-spacing: .3px;
}
.conv-section-title {
  cursor: pointer;
  user-select: none;
}
.conv-section-title .collapse-arrow {
  font-size: 10px;
  transition: transform .2s;
  margin-left: 4px;
}
.conv-section.collapsed .collapse-arrow {
  transform: rotate(-90deg);
}
.conv-section.collapsed > div:not(.conv-section-title) {
  display: none !important;
}
/* keep create-group button visible when collapsed */
.conv-section.collapsed > .conv-section-title .conv-add-btn {
  display: inline-flex;
}
.section-count {
  font-weight: 400;
  opacity: .7;
  margin-left: 2px;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    z-index: 50;
    width: 280px;
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: flex; }
  .main-content {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .chat-header {
    position: sticky;
    top: 0;
    z-index: 10;
  }
  .messages-container {
    overflow-y: visible;
    flex: 1 0 auto;
    padding: 12px 16px;
  }
  .input-area {
    position: sticky;
    bottom: 0;
    z-index: 10;
  }
  .msg { max-width: 92%; }
  .msg-image img { max-width: 160px; max-height: 160px; }
  .msg-video video { max-width: 160px; max-height: 160px; }
  .emoji-picker { left: 12px; max-width: 280px; }
  .emoji-tabs { padding: 0 2px 6px; }
  .emoji-tab { width: 28px; height: 28px; font-size: 15px; }
  .emoji-tab img { width: 20px; height: 20px; }
  .emoji-grid { grid-template-columns: repeat(7, 1fr); }
  .auth-card { padding: 32px 24px 28px; }
}

.gs-member {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.gs-member:last-child { border-bottom: none; }
.gs-empty {
  padding: 16px 4px;
  font-size: 13px;
  color: var(--text-3);
  text-align: center;
}
