* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --primary-glow: rgba(99, 102, 241, 0.35);
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.35);
  --success: #22c55e;
  --success-glow: rgba(34, 197, 94, 0.35);
  --warning: #f59e0b;
  --warning-glow: rgba(245, 158, 11, 0.35);
  --bg-darkest: #0d0d1a;
  --bg-dark: #131325;
  --bg-medium: #1a1a30;
  --bg-lighter: #202038;
  --surface: #252545;
  --surface-hover: #2d2d52;
  --border: #2e2e52;
  --text-primary: #f0f0f5;
  --text-secondary: #a0a0c0;
  --text-muted: #6b6b8a;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6);
  --nav-width: 64px;
  --sidebar-width: 280px;
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.16, 1, 0.3, 1);
}

html, body {
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-darkest);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== GLOBAL ANIMATIONS ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideDownFade {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleUpFade {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes messagePopIn {
  0% { opacity: 0; transform: translateY(10px) scale(0.97); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes logoFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-5px) rotate(-2deg); }
}

@keyframes pulseRing {
  0% { transform: scale(0.85); opacity: 0.9; }
  70% { transform: scale(2.2); opacity: 0; }
  100% { transform: scale(2.2); opacity: 0; }
}

@keyframes glowBreathing {
  0%, 100% { box-shadow: 0 0 10px var(--primary-glow); }
  50% { box-shadow: 0 0 22px var(--primary-glow), 0 0 5px var(--primary); }
}

@keyframes barSlideIn {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}

@keyframes typingWave {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-6px) scale(1.15); opacity: 1; }
}

@keyframes badgePop {
  0% { transform: scale(0); }
  70% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

@keyframes toastSlideIn {
  0% { transform: translateX(120%) scale(0.85); opacity: 0; }
  70% { transform: translateX(-4px) scale(1.02); opacity: 1; }
  100% { transform: translateX(0) scale(1); opacity: 1; }
}

@keyframes toastTimer {
  from { width: 100%; }
  to { width: 0%; }
}

/* SCREEN MANAGEMENT */
.screen { display: none; width: 100%; height: 100%; }
.screen.active {
  display: flex;
  animation: fadeIn 0.35s var(--ease-smooth);
}

/* ===== AUTH SCREEN ===== */
#authScreen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 20%, #1f1f45 0%, var(--bg-darkest) 80%);
  position: relative;
  overflow: hidden;
}

#authScreen::before {
  content: '';
  position: absolute;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(99,102,241,0.18) 0%, transparent 70%);
  top: -100px;
  right: -100px;
  border-radius: 50%;
  pointer-events: none;
  animation: logoFloat 8s ease-in-out infinite alternate;
}

#authScreen::after {
  content: '';
  position: absolute;
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, rgba(79,70,229,0.15) 0%, transparent 70%);
  bottom: -80px;
  left: -80px;
  border-radius: 50%;
  pointer-events: none;
  animation: logoFloat 10s ease-in-out infinite alternate-reverse;
}

.auth-container {
  width: 100%;
  max-width: 420px;
  padding: 20px;
  z-index: 2;
  position: relative;
}

.auth-box {
  background: rgba(37, 37, 69, 0.8);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius);
  padding: 38px 32px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 30px rgba(99, 102, 241, 0.1);
  animation: slideUpFade 0.55s var(--ease-spring) both;
  transition: transform 0.3s var(--ease-smooth), box-shadow 0.3s;
}

.auth-box:hover {
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), 0 0 35px rgba(99, 102, 241, 0.18);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.auth-logo i {
  font-size: 34px;
  color: var(--primary-light);
  filter: drop-shadow(0 0 12px var(--primary-glow));
  animation: logoFloat 4s ease-in-out infinite;
}

.auth-box h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #ffffff 0%, var(--primary-light) 50%, var(--primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-box .subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 28px;
}

.auth-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  background: var(--bg-dark);
  border-radius: var(--radius-sm);
  padding: 4px;
  border: 1px solid var(--border);
}

.auth-tabs .tab {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 600;
  border-radius: 6px;
  transition: all 0.25s var(--ease-smooth);
  font-size: 14px;
  position: relative;
}

.auth-tabs .tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.auth-tabs .tab.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 14px var(--primary-glow);
  transform: scale(1.02);
}

.auth-form {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.auth-form.active {
  display: flex;
  animation: fadeIn 0.3s var(--ease-smooth);
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group i {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
  transition: color 0.2s, transform 0.2s;
}

.input-group input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  transition: all 0.25s var(--ease-smooth);
}

.input-group input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-medium);
  box-shadow: 0 0 0 3px var(--primary-glow);
  transform: translateY(-1px);
}

.input-group input:focus ~ i {
  color: var(--primary-light);
  transform: scale(1.1);
}

.input-group input::placeholder { color: var(--text-muted); }

.error-message {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  text-align: center;
  animation: slideDownFade 0.25s var(--ease-smooth);
}

/* ===== BUTTONS ===== */
.btn-primary {
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s var(--ease-smooth);
  font-size: 14px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.btn-primary::after {
  content: '';
  position: absolute;
  top: 0; left: -100%; width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s ease;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(99, 102, 241, 0.45);
}

.btn-primary:hover::after {
  left: 100%;
}

.btn-primary:active {
  transform: translateY(0) scale(0.98);
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--bg-lighter);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s var(--ease-smooth);
  font-size: 14px;
  flex-shrink: 0;
}

.btn-icon:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  transform: translateY(-1px) scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.btn-icon:active {
  transform: translateY(0) scale(0.95);
}

.btn-icon.danger:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-send {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s var(--ease-spring);
  font-size: 15px;
  flex-shrink: 0;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-send:hover:not(:disabled) {
  transform: scale(1.12) rotate(6deg);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.55);
}

.btn-send:active:not(:disabled) {
  transform: scale(0.92) rotate(-3deg);
}

.btn-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-attach {
  width: 40px;
  height: 40px;
  background: var(--bg-lighter);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s var(--ease-smooth);
  font-size: 15px;
  flex-shrink: 0;
}

.btn-attach:hover {
  background: var(--surface-hover);
  color: var(--primary-light);
  transform: scale(1.08) rotate(-8deg);
  border-color: var(--primary-glow);
}

.btn-attach:active {
  transform: scale(0.94);
}

.btn-back {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s var(--ease-smooth);
}

.btn-back:hover {
  color: var(--text-primary);
  transform: translateX(-2px);
}

/* ===== APP LAYOUT ===== */
.app-layout {
  display: flex;
  width: 100%;
  height: 100%;
  background: var(--bg-darkest);
}

/* NAV RAIL */
.nav-rail {
  width: var(--nav-width);
  background: var(--bg-darkest);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  gap: 6px;
  flex-shrink: 0;
  z-index: 20;
}

.nav-rail-item {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.25s var(--ease-spring);
  position: relative;
  font-size: 18px;
}

.nav-rail-item:hover {
  background: var(--surface);
  color: var(--text-primary);
  transform: translateY(-2px) scale(1.06);
}

.nav-rail-item:active {
  transform: scale(0.94);
}

.nav-rail-item.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 16px var(--primary-glow);
  transform: scale(1.04);
}

.nav-rail-item.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 12px;
  bottom: 12px;
  width: 4px;
  background: var(--primary-light);
  border-radius: 0 4px 4px 0;
  box-shadow: 0 0 10px var(--primary);
  animation: barSlideIn 0.3s var(--ease-smooth);
}

.nav-rail-spacer { flex: 1; }

.nav-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary);
  transition: transform 0.25s var(--ease-spring), box-shadow 0.25s;
}

.nav-avatar:hover {
  transform: scale(1.1);
  box-shadow: 0 0 12px var(--primary-glow);
}

.nav-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  box-shadow: 0 2px 8px var(--danger-glow);
  animation: badgePop 0.35s var(--ease-spring);
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-dark);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s var(--ease-smooth);
}

.sidebar-panel {
  display: none;
  flex-direction: column;
  height: 100%;
}

.sidebar-panel.active {
  display: flex;
  animation: fadeIn 0.25s var(--ease-smooth);
}

.sidebar-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-header h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.sidebar-actions { display: flex; gap: 6px; }

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  scroll-behavior: smooth;
}

.sidebar-content::-webkit-scrollbar { width: 5px; }
.sidebar-content::-webkit-scrollbar-track { background: transparent; }
.sidebar-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* List items */
.list-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.2s var(--ease-smooth);
  margin-bottom: 4px;
  position: relative;
}

.list-item:hover {
  background: var(--surface);
  transform: translateX(4px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

.list-item:active {
  transform: translateX(2px) scale(0.98);
}

.list-item.active {
  background: rgba(99, 102, 241, 0.16);
  border-left: 3px solid var(--primary);
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.15);
}

.list-item-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.06);
  transition: transform 0.2s var(--ease-smooth);
}

.list-item:hover .list-item-avatar {
  transform: scale(1.05);
}

.list-item-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--primary-light);
  border: 1px solid rgba(255,255,255,0.06);
  transition: transform 0.2s var(--ease-smooth);
}

.list-item:hover .list-item-icon {
  transform: scale(1.05);
}

.list-item-info { flex: 1; min-width: 0; }
.list-item-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item-sub { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.list-item-badge {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  box-shadow: 0 0 8px var(--success);
  position: relative;
}

.list-item-badge::after {
  content: '';
  position: absolute;
  top: -2px; left: -2px; right: -2px; bottom: -2px;
  border-radius: 50%;
  border: 1.5px solid var(--success);
  animation: pulseRing 2.2s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
  animation: fadeIn 0.4s var(--ease-smooth);
}

.empty-state i {
  font-size: 44px;
  margin-bottom: 14px;
  opacity: 0.4;
  animation: logoFloat 4s ease-in-out infinite;
}

.empty-state p { font-size: 13px; line-height: 1.5; }

/* ===== PROFILE PANEL ===== */
.profile-content {
  padding: 24px 18px;
  animation: fadeIn 0.3s var(--ease-smooth);
}

.profile-avatar-wrapper {
  position: relative;
  width: 86px;
  height: 86px;
  margin: 0 auto 16px;
}

.profile-avatar {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--primary);
  box-shadow: 0 0 20px var(--primary-glow);
  transition: transform 0.3s var(--ease-spring);
}

.profile-avatar-wrapper:hover .profile-avatar {
  transform: scale(1.05);
}

.avatar-upload-btn {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  border: 2px solid var(--bg-dark);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: all 0.2s var(--ease-spring);
}

.avatar-upload-btn:hover {
  background: var(--primary-dark);
  transform: scale(1.15);
}

.profile-info { text-align: center; margin-bottom: 22px; }

.profile-username-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.profile-username { font-size: 18px; font-weight: 700; }
.profile-nickname { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

.admin-badge {
  background: linear-gradient(135deg, var(--warning), #d97706);
  color: #1a1a2e;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 2px 8px var(--warning-glow);
}

.admin-badge-sm {
  color: var(--warning);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  filter: drop-shadow(0 0 6px var(--warning-glow));
}

.profile-field { margin-bottom: 16px; }
.profile-field label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 600;
}

.profile-field input, .profile-field textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-medium);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  resize: none;
  font-family: inherit;
  transition: all 0.2s var(--ease-smooth);
}

.profile-field input:focus, .profile-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  transform: translateY(-1px);
}

/* ===== MAIN CHAT ===== */
.main-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-medium);
  min-width: 0;
  position: relative;
}

.chat-header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-dark);
  flex-shrink: 0;
  z-index: 10;
}

.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1.5px solid var(--border);
  transition: transform 0.2s var(--ease-smooth);
}

.chat-avatar:hover {
  transform: scale(1.08);
}

.chat-header-info { flex: 1; min-width: 0; }

.chat-title-row { display: flex; align-items: center; gap: 8px; }
.chat-title { font-size: 16px; font-weight: 700; }
.chat-subtitle { font-size: 12px; color: var(--text-muted); }

.chat-header-actions { display: flex; gap: 6px; }

/* Channel bar */
.channel-bar {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-dark);
  flex-shrink: 0;
  overflow-x: auto;
}

.channels-list {
  display: flex;
  gap: 6px;
  flex: 1;
  overflow-x: auto;
  padding: 2px 0;
}

.channel-item {
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.2s var(--ease-smooth);
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
}

.channel-item:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  transform: translateY(-1px);
  border-color: var(--border);
}

.channel-item.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 2px 10px var(--primary-glow);
  transform: scale(1.02);
}

#addChannelBtn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: all 0.2s var(--ease-spring);
}

#addChannelBtn:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: translateY(-1px) scale(1.08);
  box-shadow: 0 2px 10px var(--primary-glow);
}

#addChannelBtn:active {
  transform: scale(0.95);
}

/* Messages */
.messages-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.messages-area::-webkit-scrollbar { width: 6px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.message-row {
  display: flex;
  gap: 12px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  position: relative;
  transition: background 0.15s, transform 0.15s;
  animation: messagePopIn 0.28s var(--ease-spring) both;
}

.message-row:hover {
  background: rgba(255, 255, 255, 0.035);
}

.message-row:hover .message-actions {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.message-row.continued { padding-top: 2px; }
.message-row.continued .msg-avatar { display: none; }
.message-row.continued .msg-header { display: none; }

.msg-time-gutter {
  width: 38px;
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0;
  text-align: right;
  padding-right: 4px;
  user-select: none;
  flex-shrink: 0;
  margin-top: 3px;
  transition: opacity 0.15s;
}

.message-row.continued:hover .msg-time-gutter {
  opacity: 1;
}

.msg-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  margin-top: 2px;
  cursor: pointer;
  transition: transform 0.2s var(--ease-smooth);
}

.msg-avatar:hover {
  transform: scale(1.1);
}

.msg-content { flex: 1; min-width: 0; }

.msg-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}

.msg-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
  transition: color 0.15s;
}

.msg-name:hover {
  color: var(--primary-light);
  text-decoration: underline;
}

.msg-admin-icon {
  color: var(--warning);
  font-size: 11px;
  filter: drop-shadow(0 0 6px var(--warning-glow));
}

.verified-badge {
  color: #22d3ee;
  font-size: 12px;
  filter: drop-shadow(0 0 5px rgba(34, 211, 238, 0.7));
  animation: badge-pulse 3s ease-in-out infinite;
}

.verified-badge-sm {
  font-size: 11px;
  vertical-align: middle;
}

@keyframes badge-pulse {
  0%, 100% { filter: drop-shadow(0 0 4px rgba(34, 211, 238, 0.6)); }
  50% { filter: drop-shadow(0 0 10px rgba(34, 211, 238, 1)); }
}

.msg-time {
  font-size: 11px;
  color: var(--text-muted);
  user-select: none;
}

.msg-bubble {
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-primary);
  word-break: break-word;
  white-space: pre-wrap;
  display: inline-block;
  max-width: 100%;
}

.msg-bubble-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: 8px;
  opacity: 0.75;
  user-select: none;
  font-weight: 500;
  display: inline-block;
  white-space: nowrap;
}

.msg-image-wrapper {
  position: relative;
  display: inline-block;
  margin-top: 6px;
}

.msg-image-time {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  color: #f1f5f9;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 6px;
  user-select: none;
}

.msg-edited { font-size: 11px; color: var(--text-muted); font-style: italic; }

.msg-image {
  max-width: 300px;
  max-height: 300px;
  border-radius: 10px;
  cursor: pointer;
  display: block;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: transform 0.25s var(--ease-smooth), box-shadow 0.25s;
}

.msg-image:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.msg-reply-quote {
  border-left: 3px solid var(--primary);
  padding: 5px 12px;
  margin-bottom: 6px;
  background: rgba(99, 102, 241, 0.09);
  border-radius: 0 8px 8px 0;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}

.msg-reply-quote:hover {
  background: rgba(99, 102, 241, 0.16);
  transform: translateX(2px);
}

.msg-reply-quote.parent-deleted {
  border-left-color: var(--danger);
  background: rgba(239, 68, 68, 0.08);
  cursor: default;
}
.msg-reply-quote.parent-deleted:hover {
  transform: none;
}

.msg-reply-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.msg-reply-author { font-size: 12px; font-weight: 700; color: var(--primary-light); }
.msg-reply-quote.parent-deleted .msg-reply-author { color: var(--danger); }

.msg-reply-text { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }

.btn-delete-parent {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 11px;
  border-radius: 4px;
  transition: all 0.15s;
}

.btn-delete-parent:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.15);
}

.msg-reply-jump {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 10px;
  opacity: 0.6;
  transition: all 0.15s;
  padding: 2px 4px;
  border-radius: 4px;
}

.msg-reply-quote:hover .msg-reply-jump {
  color: var(--primary-light);
  opacity: 1;
  background: rgba(99,102,241,0.15);
}

.msg-deleted {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.msg-deleted-time {
  font-size: 10px;
  opacity: 0.7;
  font-style: normal;
  margin-left: 6px;
}

.message-actions {
  position: absolute;
  top: -10px;
  right: 12px;
  display: flex;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  opacity: 0;
  transform: translateY(4px);
  transition: all 0.2s var(--ease-smooth);
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

.message-actions button {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: all 0.15s var(--ease-spring);
}

.message-actions button:hover {
  background: var(--bg-lighter);
  color: var(--text-primary);
  transform: scale(1.15);
}

.message-actions button.danger:hover { color: var(--danger); }

/* Typing indicator */
.typing-indicator {
  height: 0;
  overflow: hidden;
  transition: height 0.25s var(--ease-smooth), padding 0.25s ease;
}

.typing-indicator.active {
  height: 32px;
  padding: 2px 18px;
}

.typing-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  font-size: 12px;
  color: var(--text-secondary);
  background: rgba(99, 102, 241, 0.08);
  padding: 4px 12px;
  border-radius: 12px;
  border: 1px solid rgba(99, 102, 241, 0.15);
  width: fit-content;
  animation: fadeIn 0.25s var(--ease-smooth);
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary-light);
  box-shadow: 0 0 6px var(--primary);
  animation: typingWave 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Reply preview */
.reply-preview, .edit-preview {
  padding: 8px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
  animation: slideDownFade 0.25s var(--ease-smooth);
}

.reply-preview-content, .edit-preview-content {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.reply-preview-content i { color: var(--primary-light); }
.edit-preview-content i { color: var(--warning); }

.reply-preview-text { display: flex; flex-direction: column; min-width: 0; }
#replyPreviewAuthor { font-size: 12px; font-weight: 700; color: var(--primary-light); }
#replyPreviewMessage { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Message input */
.message-input-box {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  background: var(--bg-dark);
  flex-shrink: 0;
  align-items: flex-end;
}

#messageInput {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg-medium);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color 0.25s var(--ease-smooth), background 0.25s var(--ease-smooth);
  font-family: inherit;
  resize: none;
  max-height: 120px;
  min-height: 42px;
  height: 42px;
  line-height: 1.4;
  overflow-y: auto;
}

#messageInput:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  background: var(--bg-lighter);
}

#messageInput::placeholder { color: var(--text-muted); }
#messageInput:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== MODALS ===== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.25s var(--ease-smooth);
}

.modal-overlay.active {
  display: flex;
  opacity: 1;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.08);
  width: 90%;
  max-width: 440px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: scale(0.92) translateY(12px);
  transition: transform 0.3s var(--ease-spring);
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }

.modal-body {
  padding: 22px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-top: 8px;
}

.modal-close {
  width: 32px;
  height: 32px;
  font-size: 13px;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 300px;
  overflow-y: auto;
}

/* Icon upload */
.icon-upload-wrapper { display: flex; justify-content: center; margin-bottom: 8px; }
.icon-upload-label {
  cursor: pointer;
  position: relative;
  width: 76px;
  height: 76px;
  transition: transform 0.2s var(--ease-spring);
}

.icon-upload-label:hover {
  transform: scale(1.06);
}

.icon-preview {
  width: 76px;
  height: 76px;
  border-radius: 18px;
  object-fit: cover;
  border: 2px solid var(--primary);
  box-shadow: 0 4px 14px var(--primary-glow);
}

.icon-preview[src=""] { display: none; }

.icon-upload-placeholder {
  width: 76px;
  height: 76px;
  border-radius: 18px;
  background: var(--bg-medium);
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 24px;
  transition: all 0.2s var(--ease-smooth);
}

.icon-upload-label:hover .icon-upload-placeholder {
  border-color: var(--primary-light);
  color: var(--primary-light);
  background: var(--surface);
}

.icon-preview:not([src=""]) ~ .icon-upload-placeholder { display: none; }

/* Discover list */
.discover-list { display: flex; flex-direction: column; gap: 8px; }

.discover-item {
  padding: 14px;
  background: var(--bg-medium);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all 0.2s var(--ease-smooth);
  border: 1px solid transparent;
}

.discover-item:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
  border-color: var(--border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.discover-item img {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  object-fit: cover;
}

.discover-item-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--primary-light);
}

/* Image viewer */
.image-viewer {
  background: rgba(0, 0, 0, 0.94);
  backdrop-filter: blur(12px);
}

.image-viewer-content {
  position: relative;
  width: 90%;
  height: 90%;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: scaleUpFade 0.3s var(--ease-spring);
}

.image-viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  background: rgba(0, 0, 0, 0.6);
  border-color: rgba(255, 255, 255, 0.2);
}

#fullImageView {
  max-width: 90%;
  max-height: 90%;
  border-radius: 10px;
  object-fit: contain;
  box-shadow: 0 10px 40px rgba(0,0,0,0.8);
}

/* User profile modal */
.user-profile-modal-body { padding: 24px; text-align: center; }

.user-profile-avatar {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--primary);
  margin: 0 auto 14px;
  display: block;
  box-shadow: 0 0 20px var(--primary-glow);
  animation: scaleUpFade 0.35s var(--ease-spring);
}

.user-profile-name { font-size: 19px; font-weight: 700; margin-bottom: 4px; }
.user-profile-username { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }
.user-profile-desc { font-size: 14px; color: var(--text-secondary); margin-bottom: 18px; line-height: 1.5; }
.user-profile-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.profile-admin-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
  padding: 12px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.07);
  width: 100%;
}

.profile-action-btn {
  padding: 8px 14px;
  font-size: 12px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-verified {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.2), rgba(34, 211, 238, 0.1));
  border: 1px solid rgba(34, 211, 238, 0.4);
  color: #22d3ee;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-verified:hover {
  background: rgba(34, 211, 238, 0.25);
  border-color: #22d3ee;
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.3);
}

.profile-verified-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.2), rgba(34, 211, 238, 0.1));
  border: 1px solid rgba(34, 211, 238, 0.4);
  color: #22d3ee;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: 0.3px;
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.25);
  vertical-align: middle;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: rgba(37, 37, 69, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastSlideIn 0.35s var(--ease-spring) both;
  max-width: 320px;
  position: relative;
  overflow: hidden;
}

.toast::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2.5px;
  width: 100%;
  background: currentColor;
  opacity: 0.6;
  animation: toastTimer 3s linear forwards;
}

.toast.success { border-left: 4px solid var(--success); color: var(--text-primary); }
.toast.success i { color: var(--success); }

.toast.error { border-left: 4px solid var(--danger); color: var(--text-primary); }
.toast.error i { color: var(--danger); }

.toast.info { border-left: 4px solid var(--primary); color: var(--text-primary); }
.toast.info i { color: var(--primary-light); }

.channel-delete-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 5px;
  font-size: 11px;
  border-radius: 4px;
  opacity: 0;
  transition: all 0.15s var(--ease-smooth);
}

.channel-item:hover .channel-delete-btn { opacity: 1; }
.channel-delete-btn:hover { color: var(--danger); background: rgba(239, 68, 68, 0.15); }

/* MEMBERS PANEL */
.members-panel {
  width: 240px;
  background: var(--bg-dark);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  animation: fadeIn 0.25s var(--ease-smooth);
}

.members-panel-header {
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.members-panel-header h3 { font-size: 14px; font-weight: 700; }

.members-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.members-list::-webkit-scrollbar { width: 5px; }
.members-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.member-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 3px;
  transition: all 0.15s var(--ease-smooth);
  position: relative;
}

.member-item:hover {
  background: var(--surface);
  transform: translateX(2px);
}

.member-item-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.member-item-info { flex: 1; min-width: 0; }

.member-item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-item-role {
  font-size: 11px;
  color: var(--text-muted);
}

.member-item-role.owner { color: var(--warning); }
.member-item-role.admin { color: var(--primary-light); }
.member-item-role.muted { color: var(--danger); }

.member-actions {
  display: none;
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  gap: 2px;
  background: var(--bg-medium);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
  z-index: 5;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  animation: scaleUpFade 0.2s var(--ease-spring);
}

.member-item:hover .member-actions { display: flex; }
.member-item:hover .member-item-info { margin-right: 100px; }

.member-actions button {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: all 0.15s var(--ease-spring);
}

.member-actions button:hover {
  background: var(--bg-lighter);
  color: var(--text-primary);
  transform: scale(1.15);
}

.member-actions button.danger:hover { color: var(--danger); }
.member-actions button.warn:hover { color: var(--warning); }
.member-actions button.secondary:hover { color: #10b981; }

.member-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  font-weight: 600;
}
.member-badge.owner { background: var(--warning); color: #1a1a2e; }
.member-badge.admin { background: var(--primary); color: white; }
.member-badge.moderator { background: #10b981; color: white; }
.member-badge.muted { background: var(--danger); color: white; }
.channel-item.locked { opacity: 0.7; }
.channel-item.locked i.fa-lock { color: var(--danger); }

/* ===== SETTINGS STYLES ===== */
.modal-lg {
  max-width: 580px;
  width: 92%;
}

.modal-title-with-icon {
  display: flex;
  align-items: center;
  gap: 10px;
}
.modal-title-with-icon i {
  color: var(--primary-light);
  font-size: 18px;
}

.settings-nav-tabs {
  display: flex;
  gap: 6px;
  padding: 8px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-dark);
  overflow-x: auto;
}

.settings-tab {
  padding: 8px 14px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  border-radius: 6px;
  transition: all 0.2s var(--ease-smooth);
  white-space: nowrap;
}

.settings-tab:hover {
  background: var(--surface);
  color: var(--text-primary);
}

.settings-tab.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 10px var(--primary-glow);
}

.settings-tab.danger:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}
.settings-tab.danger.active {
  background: var(--danger);
  color: white;
  box-shadow: 0 2px 10px var(--danger-glow);
}

.settings-modal-body {
  padding: 20px;
  overflow-y: auto;
  max-height: 60vh;
}

.settings-panel-content {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.settings-panel-content.active {
  display: flex;
  animation: fadeIn 0.25s var(--ease-smooth);
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.settings-field input, .settings-field textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s;
}

.settings-field input:focus, .settings-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  transition: border-color 0.2s;
}

.settings-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.settings-card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.settings-card-title i {
  color: var(--primary-light);
}

.color-picker-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.color-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.25s var(--ease-spring);
  border: 2px solid transparent;
}

.color-dot:hover {
  transform: scale(1.15);
}

.color-dot.active {
  border: 2.5px solid white;
  transform: scale(1.2);
  box-shadow: 0 0 14px currentColor;
}

.theme-picker-row {
  display: flex;
  gap: 6px;
}

.theme-btn {
  flex: 1;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s var(--ease-smooth);
}

.theme-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.theme-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 10px var(--primary-glow);
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 7px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.toggle-row:last-child {
  border-bottom: none;
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 22px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  transition: 0.25s var(--ease-smooth);
  border-radius: 22px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-secondary);
  transition: 0.25s var(--ease-spring);
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
}

input:checked + .slider:before {
  transform: translateX(20px);
  background-color: white;
}

.danger-box {
  border: 1px solid rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.06);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.danger-box-info h4 {
  font-size: 14px;
  font-weight: 700;
  color: var(--danger);
  margin-bottom: 2px;
}

.danger-box-info p {
  font-size: 12px;
  color: var(--text-muted);
}

.btn-danger {
  background: var(--danger);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s var(--ease-smooth);
  box-shadow: 0 2px 10px var(--danger-glow);
  white-space: nowrap;
}

.btn-danger:hover {
  background: #dc2626;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--danger-glow);
}

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--surface-hover);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.settings-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.settings-section-header h4 {
  font-size: 14px;
  font-weight: 700;
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}

.settings-row-item {
  padding: 10px 12px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: all 0.15s;
}

.settings-row-item:hover {
  background: var(--bg-medium);
  border-color: rgba(255, 255, 255, 0.12);
}

.settings-row-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.settings-row-info img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.settings-row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.search-mini input {
  padding: 6px 10px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
}
.search-mini input:focus {
  border-color: var(--primary);
}

/* Compact mode */
body.compact-mode .message-row {
  padding: 2px 8px;
}
body.compact-mode .msg-avatar {
  width: 30px;
  height: 30px;
}
body.compact-mode .messages-area {
  gap: 2px;
  padding: 10px 12px;
}

/* ===== UNIFIED MOBILE & TABLET RESPONSIVE (MAX-WIDTH: 768px) ===== */
@media (max-width: 768px) {
  html, body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .app-layout {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    position: relative;
    overflow: hidden;
  }

  /* Bottom Navigation Bar on Mobile */
  .nav-rail {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 60px !important;
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-around !important;
    align-items: center !important;
    background: var(--bg-dark) !important;
    border-right: none !important;
    border-top: 1px solid var(--border) !important;
    padding: 0 10px !important;
    padding-bottom: max(6px, env(safe-area-inset-bottom)) !important;
    z-index: 1000 !important;
    flex-shrink: 0;
  }

  .nav-rail-spacer {
    display: none !important;
  }

  .nav-rail-item {
    width: 44px !important;
    height: 44px !important;
    font-size: 18px !important;
    border-radius: 12px !important;
  }

  .nav-avatar {
    width: 32px !important;
    height: 32px !important;
  }

  /* Mobile Sidebar (List View) */
  .sidebar {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: calc(100% - 60px) !important;
    height: calc(100dvh - 60px) !important;
    z-index: 50 !important;
    background: var(--bg-darkest) !important;
    border-right: none !important;
    box-shadow: none !important;
    display: flex !important;
    flex-direction: column !important;
  }

  .sidebar.mobile-hidden {
    display: none !important;
  }

  /* Mobile Main Chat (Chat View) */
  .main-chat {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: calc(100% - 60px) !important;
    height: calc(100dvh - 60px) !important;
    z-index: 60 !important;
    background: var(--bg-darkest) !important;
    display: flex !important;
    flex-direction: column !important;
  }

  .main-chat.mobile-hidden {
    display: none !important;
  }

  .btn-back {
    display: flex !important;
  }

  .messages-container {
    flex: 1;
    overflow-y: auto;
  }

  .messages-area {
    padding: 12px;
  }

  .message-input-box {
    padding: 10px 12px;
  }

  .msg-image {
    max-width: 220px;
    max-height: 220px;
  }

  .message-actions {
    opacity: 1;
    pointer-events: auto;
  }

  .members-panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 70;
    width: 100%;
    max-width: 280px;
    box-shadow: -10px 0 30px rgba(0,0,0,0.5);
  }

  .auth-box {
    padding: 28px 20px;
    width: 92%;
  }

  input, textarea, select {
    font-size: 16px !important; /* Prevents auto-zoom on mobile safari/chrome */
  }

  .modal {
    width: 95%;
    max-height: 90vh;
    border-radius: 16px;
  }
}

/* Edit Muted & Danger Soft Buttons */
.btn-icon.muted-active {
  color: var(--warning);
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.3);
}

.btn-icon.btn-danger-soft {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.25);
}

.btn-icon.btn-danger-soft:hover {
  background: var(--danger);
  color: #fff;
}

/* ===== NEW FEATURE STYLES ===== */

/* Markdown text formatting */
.msg-h1 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 4px 0;
  color: var(--primary-light);
}

.msg-h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 3px 0;
  color: var(--text-primary);
}

.msg-subtext {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
  margin: 2px 0;
}

.msg-bullet {
  margin-left: 16px;
  list-style-type: disc;
}

.msg-link {
  color: var(--primary-light);
  text-decoration: underline;
  word-break: break-all;
}

.msg-link:hover {
  color: #fff;
}

/* Mentions */
.mention-badge {
  background: var(--primary-glow);
  color: var(--primary-light);
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.mention-badge.mention-me {
  background: rgba(245, 158, 11, 0.25);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.mention-popover {
  position: absolute;
  bottom: 60px;
  left: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 100;
  display: flex;
  flex-direction: column;
  min-width: 180px;
  overflow: hidden;
}

.mention-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  transition: background 0.15s ease;
}

.mention-item:hover {
  background: var(--surface-hover);
}

.mention-item-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
}

/* Video media in chat */
.msg-video {
  max-width: 320px;
  max-height: 240px;
  border-radius: 12px;
  outline: none;
  background: #000;
  margin-top: 4px;
}

/* Reactions */
.reaction-quick-bar {
  display: flex;
  gap: 2px;
  margin-right: 4px;
  border-right: 1px solid var(--border);
  padding-right: 4px;
}

.reaction-quick-bar button {
  width: 24px !important;
  height: 24px !important;
  font-size: 13px !important;
}

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--bg-medium);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.reaction-pill:hover {
  background: var(--surface-hover);
  border-color: var(--primary);
}

.reaction-pill.active {
  background: var(--primary-glow);
  border-color: var(--primary);
  color: var(--primary-light);
}

/* Suspended user badge */
.profile-suspended-badge {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.4);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

/* Hidden message box */
.msg-hidden-box {
  background: rgba(255, 255, 255, 0.05);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary-light);
  text-decoration: underline;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}

/* ===== CUSTOM EMOJI STYLES ===== */
.inline-custom-emoji {
  width: 24px;
  height: 24px;
  vertical-align: middle;
  object-fit: contain;
  display: inline-block;
  margin: 0 2px;
}

.reaction-custom-emoji {
  width: 18px;
  height: 18px;
  object-fit: contain;
  vertical-align: middle;
}

/* Emoji Picker Popover */
.emoji-picker-popover {
  position: absolute;
  bottom: 64px;
  left: 60px;
  width: 310px;
  height: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fadeIn 0.2s ease;
}

.emoji-picker-tabs {
  display: flex;
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border);
}

.emoji-tab {
  flex: 1;
  padding: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.emoji-tab:hover {
  color: var(--text-primary);
}

.emoji-tab.active {
  color: var(--primary-light);
  border-bottom: 2px solid var(--primary);
  background: rgba(99, 102, 241, 0.08);
}

.emoji-picker-content {
  display: none;
  padding: 10px;
  overflow-y: auto;
  flex: 1;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  align-content: start;
}

.emoji-picker-content.active {
  display: grid;
}

.emoji-picker-item {
  background: none;
  border: none;
  border-radius: 6px;
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease;
}

.emoji-picker-item:hover {
  background: var(--surface-hover);
  transform: scale(1.18);
}

.emoji-picker-item.custom img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.empty-emoji-text {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 20px 10px;
}

/* Upload Emoji Settings Form & Grid */
.upload-emoji-card {
  background: var(--bg-medium);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.emoji-grid-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.emoji-grid-item {
  background: var(--bg-medium);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}

.emoji-grid-item img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.emoji-grid-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.emoji-grid-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary-light);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Reaction Picker Trigger (+) Button */
.reaction-picker-trigger {
  color: var(--text-muted) !important;
  font-size: 11px !important;
  border-left: 1px solid var(--border);
  padding-left: 4px !important;
}

.reaction-picker-trigger:hover {
  color: var(--primary-light) !important;
}

/* Floating Reaction Emoji Picker */
.reaction-picker-popover {
  position: absolute;
  width: 290px;
  height: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  z-index: 300;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fadeIn 0.15s ease;
}

.reaction-picker-tabs {
  display: flex;
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border);
}

.reaction-tab {
  flex: 1;
  padding: 7px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.reaction-tab:hover {
  color: var(--text-primary);
}

.reaction-tab.active {
  color: var(--primary-light);
  border-bottom: 2px solid var(--primary);
  background: rgba(99, 102, 241, 0.08);
}

.reaction-picker-grid {
  display: none;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  align-content: start;
}

.reaction-picker-grid.active {
  display: grid;
}
