/* ═══════════════════════════════════════════════════════
   Tenord Messenger — Premium Design System & Animations
   ═══════════════════════════════════════════════════════ */

/* ─── CSS Variables (Light Theme) ──────────────────── */
:root {
  /* Primary */
  --primary: #6c5ce7;
  --primary-light: #a29bfe;
  --primary-dark: #5341d6;
  --primary-bg: rgba(108, 92, 231, 0.08);
  --primary-bg-hover: rgba(108, 92, 231, 0.14);
  --primary-glow: rgba(108, 92, 231, 0.25);

  /* Background */
  --bg-main: #f0f2f5;
  --bg-sidebar: #ffffff;
  --bg-chat: #e8ecf1;
  --bg-input: #ffffff;
  --bg-hover: rgba(0, 0, 0, 0.04);
  --bg-active: rgba(108, 92, 231, 0.1);
  --bg-modal: #ffffff;
  --bg-overlay: rgba(0, 0, 0, 0.45);
  --bg-tooltip: #333;
  --bg-ripple: rgba(0, 0, 0, 0.08);

  /* Messages */
  --msg-in: #ffffff;
  --msg-out: #effdde;
  --msg-out-hover: #e2faca;
  --text-primary: #000000;
  --text-secondary: #707579;
  --text-tertiary: #aaaaaa;
  --text-danger: #e53935;
  --text-link: #6c5ce7;
  --border: #dfe1e5;
  --border-input: #dfe1e5;
  --border-light: rgba(0,0,0,0.06);

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
  --shadow-lg: 0 12px 24px rgba(0,0,0,0.15);
  --shadow-xl: 0 20px 40px rgba(0,0,0,0.2);
  --shadow-glow: 0 0 20px var(--primary-glow);

  /* Radii */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 50%;

  /* Transitions */
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-spring: 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition-bounce: 0.6s cubic-bezier(0.68, -0.55, 0.27, 1.55);

  /* Layout */
  --sidebar-width: 360px;
  --header-height: 60px;
  --input-height: 56px;
  --avatar-sm: 36px;
  --avatar-md: 48px;
  --avatar-lg: 80px;
  --avatar-xl: 96px;

  /* Z-index */
  --z-sidebar: 100;
  --z-modal: 1000;
  --z-dropdown: 500;
  --z-context: 600;
  --z-toast: 9999;

  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* ─── Dark Theme ───────────────────────────────────── */
[data-theme="dark"] {
  --primary: #3390ec;
  --primary-light: #5fa8f5;
  --primary-dark: #2b7cd1;
  --primary-bg: rgba(51, 144, 236, 0.15);
  --primary-glow: rgba(51, 144, 236, 0.3);
  --bg-main: #0e1621;
  --bg-sidebar: #17212b;
  --bg-chat: #0e1621;
  --bg-hover: #232e3c;
  --bg-active: #2b5278;
  --bg-modal: #17212b;
  --bg-input: #242f3d;
  --bg-ripple: rgba(255, 255, 255, 0.08);
  --text-primary: #ffffff;
  --text-secondary: #7f91a4;
  --text-tertiary: #6c7883;
  --text-danger: #e53935;
  --text-link: #5fa8f5;
  --msg-in: #18222d;
  --msg-out: #2b5278;
  --border: #101921;
  --border-input: #2a3540;
  --border-light: rgba(255,255,255,0.06);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 12px 24px rgba(0,0,0,0.4);
  --shadow-xl: 0 20px 40px rgba(0,0,0,0.5);
}

/* ─── Reset & Base ─────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

@media (max-width: 1024px) { html { font-size: 15px; } }
@media (max-width: 768px) { html { font-size: 14px; } }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  height: 100%;
  height: 100dvh;
  width: 100vw;
  position: fixed;
  /* Global theme transition */
  transition: background 0.5s ease, color 0.3s ease;
}

/* Smooth theme transitions on ALL themed elements */
body *, body *::before, body *::after {
  transition-property: background-color, border-color, color, box-shadow, opacity;
  transition-duration: 0.3s;
  transition-timing-function: ease;
}

/* Exclude elements that have their own specific transitions */
.message, .message *, .chat-item, .emoji-item, .btn, .icon-btn, 
input, textarea, a, .fab-btn, .scroll-bottom-btn {
  transition: all var(--transition-fast);
}

input, textarea, button {
  font-family: inherit;
  font-size: inherit;
}

a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* Scrollbar - Hidden globally */
::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}
* {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

/* ─── Ripple Effect ────────────────────────────────── */
.ripple-container {
  position: relative;
  overflow: hidden;
}

.ripple {
  position: absolute;
  border-radius: 50%;
  background: var(--bg-ripple);
  transform: scale(0);
  animation: rippleExpand 0.6s ease-out forwards;
  pointer-events: none;
}

@keyframes rippleExpand {
  to { transform: scale(4); opacity: 0; }
}

/* ═══════════════════════════════════════════════════════
   AUTH SCREEN
   ═══════════════════════════════════════════════════════ */

.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  width: 100vw;
  background: linear-gradient(135deg, #0e0e10 0%, #1a1a2e 30%, #2d1b69 60%, #6c5ce7 100%);
  background-size: 400% 400%;
  animation: authBgShift 12s ease infinite;
  padding: 20px;
  /* Animated particles */
  position: relative;
  overflow: hidden;
}

.auth-screen::before,
.auth-screen::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.15;
  animation: floatBlob 20s ease-in-out infinite;
}

.auth-screen::before {
  width: 400px; height: 400px;
  background: #6c5ce7;
  top: -100px; left: -100px;
}

.auth-screen::after {
  width: 350px; height: 350px;
  background: #a29bfe;
  bottom: -80px; right: -80px;
  animation-delay: -10s;
  animation-direction: reverse;
}

@keyframes floatBlob {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(50px, 80px) scale(1.1); }
  50% { transform: translate(-30px, 50px) scale(0.95); }
  75% { transform: translate(70px, -30px) scale(1.05); }
}

@keyframes authBgShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.auth-container {
  width: 100%;
  max-width: 400px;
  background: rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  padding: 48px 36px;
  box-shadow: 0 32px 64px rgba(0, 0, 0, 0.3);
  animation: authSlideUp 0.8s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  z-index: 1;
}

@keyframes authSlideUp {
  from { opacity: 0; transform: translateY(40px) scale(0.95); filter: blur(8px); }
  to { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}

.auth-logo {
  text-align: center;
  margin-bottom: 36px;
}

.auth-logo-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 8px rgba(108, 92, 231, 0.3)); }
  50% { transform: scale(1.08); filter: drop-shadow(0 0 24px rgba(108, 92, 231, 0.6)); }
}

.auth-logo-icon svg { width: 100%; height: 100%; }

.auth-title {
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
  animation: titleGlow 4s ease-in-out infinite;
}

@keyframes titleGlow {
  0%, 100% { text-shadow: 0 0 10px rgba(162, 155, 254, 0); }
  50% { text-shadow: 0 0 20px rgba(162, 155, 254, 0.3); }
}

.auth-subtitle {
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.9rem;
  margin-top: 6px;
}

/* ─── Auth Forms ───────────────────────────────────── */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-group {
  position: relative;
  animation: formGroupSlideIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.form-group:nth-child(1) { animation-delay: 0.1s; }
.form-group:nth-child(2) { animation-delay: 0.2s; }
.form-group:nth-child(3) { animation-delay: 0.3s; }
.form-group:nth-child(4) { animation-delay: 0.4s; }

@keyframes formGroupSlideIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.form-input {
  width: 100%;
  padding: 24px 16px 8px;
  background: rgba(255, 255, 255, 0.07);
  border: 1.5px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 0.95rem;
  outline: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.form-input:focus {
  border-color: var(--primary-light);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.15), 0 0 20px rgba(108, 92, 231, 0.1);
  transform: translateY(-1px);
}

.form-input::placeholder { color: transparent; }

.form-label {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.95rem;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.form-input:focus ~ .form-label,
.form-input:not(:placeholder-shown) ~ .form-label {
  top: 8px;
  transform: translateY(0);
  font-size: 0.72rem;
  color: var(--primary-light);
}

.form-textarea {
  resize: none;
  min-height: 80px;
  padding-top: 24px;
}

.form-textarea ~ .form-label { top: 16px; transform: none; }

.form-textarea:focus ~ .form-label,
.form-textarea:not(:placeholder-shown) ~ .form-label {
  top: 6px;
  font-size: 0.7rem;
}

.form-error {
  color: #ff6b6b;
  font-size: 0.82rem;
  min-height: 20px;
  animation: shakeError 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes shakeError {
  0%, 100% { transform: translateX(0); }
  10%, 50%, 90% { transform: translateX(-4px); }
  30%, 70% { transform: translateX(4px); }
}

/* Messenger context form inputs */
.messenger .form-input,
.modal .form-input {
  background: var(--bg-input);
  border-color: var(--border-input);
  color: var(--text-primary);
}

.messenger .form-input:focus,
.modal .form-input:focus {
  border-color: var(--primary);
  background: var(--bg-input);
  box-shadow: 0 0 0 4px var(--primary-bg), 0 0 16px var(--primary-glow);
  transform: translateY(-1px);
}

.messenger .form-label,
.modal .form-label { color: var(--text-tertiary); }

.messenger .form-input:focus ~ .form-label,
.messenger .form-input:not(:placeholder-shown) ~ .form-label,
.modal .form-input:focus ~ .form-label,
.modal .form-input:not(:placeholder-shown) ~ .form-label {
  color: var(--primary);
}

/* ─── Buttons ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px var(--primary-glow);
}

.btn-primary:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 8px var(--primary-glow);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn.loading .btn-text { opacity: 0; }
.btn.loading .btn-loader { display: block; }

.btn-loader {
  display: none;
  width: 20px; height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  position: absolute;
}

@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: scale(1.08);
}

.icon-btn:active {
  transform: scale(0.92);
}

.icon-btn svg { width: 20px; height: 20px; }

.auth-switch {
  text-align: center;
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.85rem;
  animation: formGroupSlideIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) backwards;
  animation-delay: 0.5s;
}

.auth-switch a {
  color: var(--primary-light);
  font-weight: 500;
  position: relative;
}

.auth-switch a::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 0;
  height: 1.5px;
  background: var(--primary-light);
  transition: width 0.3s ease;
}

.auth-switch a:hover::after { width: 100%; }
.auth-switch a:hover { text-decoration: none; }

/* ═══════════════════════════════════════════════════════
   MESSENGER LAYOUT
   ═══════════════════════════════════════════════════════ */

.messenger {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
  animation: messengerFadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes messengerFadeIn {
  from { opacity: 0; transform: scale(0.98); filter: blur(4px); }
  to { opacity: 1; transform: scale(1); filter: blur(0); }
}

/* ─── Sidebar ──────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 12px;
  height: var(--header-height);
  border-bottom: 1px solid var(--border-light);
}

.sidebar-search {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  width: 18px; height: 18px;
  color: var(--text-tertiary);
  pointer-events: none;
  transition: all 0.3s ease;
}

.search-input:focus ~ .search-icon,
.search-input:focus + .search-icon {
  color: var(--primary);
}

.search-input {
  width: 100%;
  padding: 10px 12px 10px 40px;
  background: var(--bg-hover);
  border: 1.5px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.88rem;
  outline: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.search-input:focus {
  background: var(--bg-input);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-bg);
}

.search-input::placeholder { color: var(--text-tertiary); }

.sidebar-search::after {
  content: 'Ctrl K';
  position: absolute;
  right: 12px;
  font-size: 10px;
  background: var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-tertiary);
  pointer-events: none;
  opacity: 0.6;
  transition: opacity 0.3s;
}

.search-input:focus ~ ::after { opacity: 0; }
@media (max-width: 768px) { .sidebar-search::after { display: none; } }

/* ─── Chat List ────────────────────────────────────── */
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  /* Staggered entrance animation */
  animation: chatItemSlide 0.4s cubic-bezier(0.16, 1, 0.3, 1) backwards;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-item:nth-child(1) { animation-delay: 0.02s; }
.chat-item:nth-child(2) { animation-delay: 0.04s; }
.chat-item:nth-child(3) { animation-delay: 0.06s; }
.chat-item:nth-child(4) { animation-delay: 0.08s; }
.chat-item:nth-child(5) { animation-delay: 0.10s; }
.chat-item:nth-child(6) { animation-delay: 0.12s; }
.chat-item:nth-child(7) { animation-delay: 0.14s; }
.chat-item:nth-child(8) { animation-delay: 0.16s; }
.chat-item:nth-child(9) { animation-delay: 0.18s; }
.chat-item:nth-child(10) { animation-delay: 0.20s; }

@keyframes chatItemSlide {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

.chat-item:hover {
  background: var(--bg-hover);
}

.chat-item:active {
  transform: scale(0.98);
  background: var(--bg-active);
}

.chat-item.active {
  background: var(--bg-active);
}

.chat-item.active::after {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%) scaleY(0);
  width: 3px;
  height: 24px;
  background: var(--primary);
  border-radius: 0 4px 4px 0;
  animation: activeBarReveal 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes activeBarReveal {
  to { transform: translateY(-50%) scaleY(1); }
}

.chat-item-avatar {
  position: relative;
  flex-shrink: 0;
}

.avatar {
  width: var(--avatar-md);
  height: var(--avatar-md);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.1rem;
  color: #fff;
  text-transform: uppercase;
  flex-shrink: 0;
  user-select: none;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-item:hover .avatar {
  transform: scale(1.05);
}

.avatar-sm { width: var(--avatar-sm); height: var(--avatar-sm); font-size: 0.8rem; }
.avatar-lg { width: var(--avatar-lg); height: var(--avatar-lg); font-size: 2rem; }
.avatar-xl { width: var(--avatar-xl); height: var(--avatar-xl); font-size: 2.5rem; }

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.online-indicator {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 12px; height: 12px;
  background: #2ecc71;
  border-radius: 50%;
  border: 2.5px solid var(--bg-sidebar);
  animation: onlinePulse 2s ease-in-out infinite;
}

@keyframes onlinePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.4); }
  50% { box-shadow: 0 0 0 4px rgba(46, 204, 113, 0); }
}

.chat-item-info { flex: 1; min-width: 0; }

.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.chat-item-name {
  font-weight: 600;
  font-size: 0.93rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.chat-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.chat-item-preview {
  font-size: 0.84rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.chat-item-preview .sender-name {
  color: var(--primary);
  font-weight: 500;
}

.unread-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--primary);
  color: #fff;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  animation: badgePop 0.4s var(--transition-bounce);
}

@keyframes badgePop {
  0% { transform: scale(0); }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* ─── FAB Button ───────────────────────────────────── */
.fab-btn {
  position: absolute;
  bottom: 20px;
  right: 20px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px var(--primary-glow);
  z-index: 15;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: fabBounceIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s backwards;
}

@keyframes fabBounceIn {
  from { opacity: 0; transform: scale(0) rotate(-90deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

.fab-btn:hover {
  transform: scale(1.12) rotate(8deg);
  box-shadow: 0 8px 30px var(--primary-glow);
}

.fab-btn:active {
  transform: scale(0.92) rotate(0);
}

.fab-btn svg { width: 24px; height: 24px; }

/* ─── Sidebar Menu ─────────────────────────────────── */
.sidebar-menu {
  position: absolute;
  top: 50px;
  left: 10px;
  width: 260px;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  min-width: 240px;
  z-index: var(--z-dropdown);
  animation: sidebarMenuIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: top left;
}

@keyframes sidebarMenuIn {
  from { opacity: 0; transform: scale(0.92) translateY(-8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.sidebar-menu .menu-item {
  animation: menuItemCascade 0.3s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.sidebar-menu .menu-item:nth-child(1) { animation-delay: 0.02s; }
.sidebar-menu .menu-item:nth-child(2) { animation-delay: 0.04s; }
.sidebar-menu .menu-item:nth-child(3) { animation-delay: 0.06s; }
.sidebar-menu .menu-item:nth-child(4) { animation-delay: 0.08s; }
.sidebar-menu .menu-item:nth-child(5) { animation-delay: 0.10s; }
.sidebar-menu .menu-item:nth-child(6) { animation-delay: 0.12s; }
.sidebar-menu .menu-item:nth-child(7) { animation-delay: 0.14s; }
.sidebar-menu .menu-item:nth-child(8) { animation-delay: 0.16s; }
.sidebar-menu .menu-item:nth-child(9) { animation-delay: 0.18s; }
.sidebar-menu .menu-item:nth-child(10) { animation-delay: 0.20s; }

@keyframes menuItemCascade {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

.profile-trigger-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.profile-trigger-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

.profile-trigger-btn:active {
  transform: scale(0.95);
}

.sidebar-menu-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.2s ease;
  animation: menuItemCascade 0.3s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.sidebar-menu-profile:hover { background: var(--bg-hover); }

.sidebar-profile-info { font-size: 0.9rem; line-height: 1.3; }
.sidebar-profile-info .profile-name { font-weight: 600; color: var(--text-primary); }
.sidebar-profile-info .profile-status { font-size: 0.8rem; color: #2ecc71; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all 0.2s ease;
}

.menu-item:hover {
  background: var(--bg-hover);
  padding-left: 18px;
}

.menu-item:active {
  transform: scale(0.97);
}

.menu-item svg {
  width: 20px; height: 20px;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: color 0.2s ease;
}

.menu-item:hover svg { color: var(--primary); }
.menu-item-danger { color: var(--text-danger); }
.menu-item-danger svg { color: var(--text-danger); }
.menu-item-danger:hover svg { color: var(--text-danger); }

.header-menu-container { position: relative; }

.dropdown-menu {
  position: absolute;
  top: 44px;
  right: 0;
  width: 220px;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  padding: 6px;
  z-index: var(--z-dropdown);
  animation: dropdownIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: top right;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: scale(0.9) translateY(-4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.dropdown-menu.hidden { display: none; }

.dropdown-menu .menu-item {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 8px;
}

/* ═══════════════════════════════════════════════════════
   CHAT AREA
   ═══════════════════════════════════════════════════════ */

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-chat);
  position: relative;
}

.chat-area::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23000000' fill-opacity='1'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

[data-theme="dark"] .chat-area::before {
  opacity: 0.015;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='1'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* ─── Empty State ──────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  z-index: 1;
  animation: emptyStateFade 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes emptyStateFade {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.empty-state-icon {
  width: 100px; height: 100px;
  margin-bottom: 24px;
  opacity: 0.6;
  animation: floatIcon 4s ease-in-out infinite;
}

@keyframes floatIcon {
  0%, 100% { transform: translateY(0) rotate(0); }
  50% { transform: translateY(-12px) rotate(3deg); }
}

.empty-state-icon svg { width: 100%; height: 100%; }

.empty-state-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state-text { color: var(--text-tertiary); font-size: 0.9rem; }

/* ─── Chat Header ──────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  height: var(--header-height);
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  z-index: 2;
  flex-shrink: 0;
  position: relative;
}

.chat-search-bar {
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  z-index: 5;
  display: flex;
  align-items: center;
  animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-search-inner {
  display: flex;
  align-items: center;
  background: var(--bg-main);
  border-radius: 10px;
  padding: 0 12px;
  width: 100%;
}

/* Toggle Switch Styling */
.menu-item-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toggle-switch {
  width: 36px;
  height: 20px;
  background: var(--bg-active);
  border-radius: 20px;
  position: relative;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.menu-item-toggle.active .toggle-switch {
  background: var(--primary);
}

.menu-item-toggle.active .toggle-switch::after {
  left: 18px;
}

.chat-search-inner .search-icon {
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
}

.chat-search-inner input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 0.95rem;
  min-width: 0;
}

.chat-search-inner input:focus {
  outline: none;
}

.chat-search-counter {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  padding: 0 6px;
  min-width: 50px;
  text-align: center;
}

.chat-search-nav {
  width: 32px !important;
  height: 32px !important;
  padding: 4px !important;
  flex-shrink: 0;
}

.chat-search-nav svg {
  width: 16px;
  height: 16px;
}

.chat-search-nav:disabled {
  opacity: 0.3;
  pointer-events: none;
}

/* Saved Messages avatar in chat list */
.chat-item-avatar .saved-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.chat-item-avatar .saved-icon svg {
  width: 24px;
  height: 24px;
}

/* Group / Channel avatar */
.group-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.group-avatar svg {
  stroke: rgba(255,255,255,0.9);
  fill: none;
}

/* Profile avatar group styling */
.profile-avatar-large .group-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  font-size: 2rem;
}

.profile-header .group-avatar {
  border: 4px solid rgba(255,255,255,0.3);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.profile-header .group-avatar svg {
  width: 40px;
  height: 40px;
}

/* Profile list member items */
.profile-list-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease;
}

.profile-list-item:hover {
  background: var(--bg-hover);
}

.profile-list-item:active {
  background: var(--bg-active);
}

.profile-list-info {
  flex: 1;
  min-width: 0;
}

.profile-list-name {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-list-status {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.profile-list-status.online {
  color: #2ecc71;
  font-weight: 500;
}

@keyframes headerSlideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-header-avatar {
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-header-avatar:hover { transform: scale(1.1); }
.chat-header-avatar:active { transform: scale(0.95); }

.back-btn { display: none; }

.chat-header-avatar .avatar {
  width: 42px; height: 42px;
  font-size: 1rem;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.chat-header-name {
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-status {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  transition: all 0.3s ease;
}

.chat-header-status.chat-type-info {
  color: var(--primary);
  font-weight: 500;
}

.chat-header-status.online { color: #2ecc71; }

.chat-header-status.typing {
  color: var(--primary);
}

/* Actual typing dots animation */
.typing-anim::after {
  content: '';
  animation: typingDotsAnim 1.5s ease-in-out infinite;
}

@keyframes typingDotsAnim {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

.chat-header-actions { display: flex; gap: 4px; }

/* ─── Messages ─────────────────────────────────────── */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  z-index: 1;
  scroll-behavior: smooth;
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 40px 30px;
  min-height: 100%;
  justify-content: flex-end;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  position: relative;
}

@media (max-width: 768px) {
  .messages-list { padding: 0 16px; max-width: 100%; }
}

/* Date separator */
.date-separator {
  display: flex;
  justify-content: center;
  padding: 12px 0;
  animation: dateSepFade 0.5s ease backwards;
}

@keyframes dateSepFade {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

.date-separator-label {
  background: rgba(0, 0, 0, 0.12);
  color: #fff;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.76rem;
  font-weight: 500;
  backdrop-filter: blur(12px);
}

[data-theme="dark"] .date-separator-label {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
}

/* Messages */
.message {
  max-width: 65%;
  margin-bottom: 2px;
  display: flex;
  flex-direction: column;
  position: relative;
  animation: msgSlideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.message.outgoing { align-self: flex-end; }
.message.incoming { align-self: flex-start; }

/* Different entry direction based on sender */
.message.incoming {
  animation-name: msgSlideInLeft;
}

.message.outgoing {
  animation-name: msgSlideInRight;
}

@keyframes msgSlideInLeft {
  from { opacity: 0; transform: translateX(-20px) scale(0.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes msgSlideInRight {
  from { opacity: 0; transform: translateX(20px) scale(0.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

.message-bubble {
  padding: 8px 14px 10px;
  border-radius: 20px;
  position: relative;
  word-wrap: break-word;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04), 0 0 1px rgba(0,0,0,0.08);
  line-height: 1.48;
  max-width: 100%;
  transition: box-shadow 0.25s ease, filter 0.25s ease, transform 0.25s ease;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.message-bubble:hover {
  filter: brightness(0.96);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* Outgoing */
.message.outgoing .message-bubble {
  background: linear-gradient(135deg, rgba(220, 248, 198, 0.95), rgba(204, 242, 175, 0.95));
  color: #111;
  border: 1px solid rgba(0,0,0,0.04);
}

[data-theme="dark"] .message.outgoing .message-bubble {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border: none;
  box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}

/* Incoming */
.message.incoming .message-bubble {
  background: rgba(255, 255, 255, 0.85);
  color: var(--text-primary);
  border: 1px solid rgba(0,0,0,0.05);
}

[data-theme="dark"] .message.incoming .message-bubble {
  background: rgba(30, 41, 59, 0.85);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.05);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Group border radius — Modern rounded grouping */
.message.outgoing.group-single .message-bubble { border-radius: 20px 20px 6px 20px; }
.message.outgoing.group-first .message-bubble  { border-radius: 20px 20px 6px 20px; }
.message.outgoing.group-middle .message-bubble { border-radius: 20px 6px 6px 20px; }
.message.outgoing.group-last .message-bubble   { border-radius: 20px 6px 20px 20px; }

.message.incoming.group-single .message-bubble { border-radius: 20px 20px 20px 6px; }
.message.incoming.group-first .message-bubble  { border-radius: 20px 20px 20px 6px; }
.message.incoming.group-middle .message-bubble { border-radius: 6px 20px 20px 6px; }
.message.incoming.group-last .message-bubble   { border-radius: 6px 20px 20px 20px; }

.message-sender {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 3px;
  color: var(--primary);
}

.message-reply {
  display: flex;
  padding: 8px 10px;
  margin-bottom: 6px;
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  background: rgba(108, 92, 231, 0.08);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

[data-theme="dark"] .message.outgoing .message-reply {
  background: rgba(255, 255, 255, 0.15);
  border-left-color: #fff;
}
[data-theme="dark"] .message.outgoing .message-reply-name {
  color: #fff;
}
[data-theme="dark"] .message.outgoing .message-reply-text {
  color: rgba(255, 255, 255, 0.8);
}

.message-reply:hover { 
  background: rgba(108, 92, 231, 0.12); 
  transform: scale(0.99);
}
[data-theme="dark"] .message.outgoing .message-reply:hover {
  background: rgba(255, 255, 255, 0.2);
}

.message-reply-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.message-reply-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary);
}

.message-reply-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Message content wrap — Telegram-style inline time */
.message-content-wrap {
  position: relative;
  display: inline;
}

.message-text {
  font-size: 0.93rem;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
}

.message-text a { color: var(--text-link); text-decoration: underline; }
.message-text code {
  background: rgba(0,0,0,0.06);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.88em;
}
[data-theme="dark"] .message-text code { background: rgba(255,255,255,0.08); }

/* Inline meta — sits at the end of the last line of text */
.message-meta-inline {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  float: right;
  margin-top: 4px;
  margin-left: 12px;
  position: relative;
  padding-left: 4px;
}

/* Old message-meta kept for fallback */
.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
}

.message-time {
  font-size: 0.68rem;
  opacity: 0.55;
  font-weight: 500;
  white-space: nowrap;
  letter-spacing: 0.2px;
}

.message-edited {
  font-size: 0.62rem;
  opacity: 0.5;
  font-style: italic;
}

.message-status {
  display: inline-flex;
  align-items: center;
  width: 20px; height: 14px;
  flex-shrink: 0;
  position: relative;
}

.message-status svg { width: 100%; height: 100%; }

/* Telegram-style sent (single check) */
.message-status.sent {
  color: rgba(255, 255, 255, 0.45);
}

/* Light theme sent check */
.message.outgoing .message-status.sent {
  color: rgba(0, 100, 0, 0.35);
}

[data-theme="dark"] .message.outgoing .message-status.sent {
  color: rgba(255, 255, 255, 0.45);
}

/* Telegram-style read (double check, green) */
.message-status.read {
  color: #4ac959;
  animation: checkAppear 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Light theme read check */
.message.outgoing .message-status.read {
  color: #4ac959;
}

[data-theme="dark"] .message.outgoing .message-status.read {
  color: #69d97c;
}

/* Check SVG path transitions */
.message-status .check-1,
.message-status .check-2 {
  transition: opacity 0.2s ease;
}

/* Outgoing message meta — use lighter color */
.message.outgoing .message-time { opacity: 0.65; }

@keyframes checkAppear {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

/* Highlight for search */
.message-highlight .message-bubble {
  box-shadow: 0 0 0 3px var(--primary), 0 0 20px var(--primary-glow);
  animation: highlightPulse 1s ease 2;
}

@keyframes highlightPulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--primary), 0 0 20px var(--primary-glow); }
  50% { box-shadow: 0 0 0 6px var(--primary), 0 0 30px var(--primary-glow); }
}

/* ─── Scroll Bottom Button ────────────────────────── */
.scroll-bottom-btn {
  position: absolute;
  bottom: 80px;
  right: 20px;
  width: 44px; height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-sidebar);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  animation: scrollBtnBounce 0.4s var(--transition-bounce);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes scrollBtnBounce {
  from { opacity: 0; transform: scale(0) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.scroll-bottom-btn:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: var(--shadow-xl);
}

.scroll-bottom-btn:active { transform: scale(0.9); }

.scroll-bottom-btn svg { width: 20px; height: 20px; }

.scroll-bottom-btn .unread-badge {
  position: absolute;
  top: -8px;
  left: -8px;
  background: var(--text-danger);
}

/* ─── Reply Preview ────────────────────────────────── */
.reply-preview {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  z-index: 2;
  animation: replySlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes replySlideUp {
  from { opacity: 0; transform: translateY(100%); }
  to { opacity: 1; transform: translateY(0); }
}

.reply-preview-content { flex: 1; min-width: 0; }

.reply-preview-name {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary);
}

.reply-preview-text {
  display: block;
  font-size: 0.82rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.reply-close-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: rotate(90deg);
}

.reply-close-btn svg { width: 16px; height: 16px; }

/* ─── Message Input ────────────────────────────────── */
.message-input-area {
  padding: 6px 8px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border);
  width: 100%;
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: center;
  animation: inputAreaSlide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes inputAreaSlide {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  max-width: 900px;
  padding: 2px 0;
  box-sizing: border-box;
}

.input-inner {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 0px;
  min-width: 0;
  background: var(--bg-input);
  padding: 6px 12px 6px 6px;
  border-radius: 24px;
  border: 1px solid var(--border-light);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.input-inner:focus-within {
  border-color: var(--primary-light);
  box-shadow: 0 4px 12px var(--primary-bg);
  background: var(--bg-sidebar);
}

#message-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 0.95rem;
  padding: 5px 0px;
  margin: 0 8px;
  max-height: 180px;
  outline: none;
  resize: none;
  line-height: 1.4;
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
  flex-shrink: 0;
}

.send-btn, .voice-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff !important;
  box-shadow: 0 4px 10px var(--primary-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  flex-shrink: 0;
  border: none;
  cursor: pointer;
}

.input-inner .icon-btn {
  width: 32px; height: 32px;
  color: var(--text-tertiary);
  margin-bottom: 0px;
  transition: all 0.2s ease;
}

.input-inner .icon-btn:hover {
  color: var(--primary);
  background: var(--bg-hover);
  transform: scale(1.1);
}

.send-btn:hover, .voice-btn:hover {
  background: var(--primary-dark);
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 6px 15px var(--primary-glow);
}

.send-btn:active, .voice-btn:active {
  transform: scale(0.92);
}

.send-btn svg, .voice-btn svg { width: 20px; height: 20px; }

.voice-btn {
  background: var(--bg-input);
  color: var(--text-secondary) !important;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  border: 1px solid var(--border-light);
}

.voice-btn:hover {
  background: var(--bg-hover);
  color: var(--primary) !important;
}

/* When recording is active */
.voice-btn.recording {
  background: var(--text-danger);
  color: #fff !important;
  animation: pulse 1.5s infinite;
}

/* ─── Emoji Picker ─────────────────────────────────── */
.emoji-picker {
  position: absolute;
  bottom: var(--input-height);
  left: 16px;
  width: 340px;
  height: 360px;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-dropdown);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: emojiPickerIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: bottom left;
}

@keyframes emojiPickerIn {
  from { opacity: 0; transform: scale(0.9) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.emoji-tabs {
  display: flex;
  gap: 2px;
  padding: 6px;
  border-bottom: 1px solid var(--border);
}

.emoji-tab {
  flex: 1;
  padding: 6px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.emoji-tab:hover { background: var(--bg-hover); transform: scale(1.1); }
.emoji-tab.active { background: var(--primary-bg); transform: scale(1.05); }

.emoji-grid {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  align-content: start;
}

.emoji-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 1.3rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.emoji-item:hover {
  background: var(--bg-hover);
  transform: scale(1.3);
}

/* ─── Attach Menu ──────────────────────────────────── */
.attach-menu {
  position: absolute;
  bottom: calc(var(--input-height) + 10px);
  left: 60px;
  width: 280px;
  background: var(--bg-modal);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-dropdown);
  display: flex;
  flex-direction: column;
  padding: 8px 0;
  animation: emojiPickerIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: bottom left;
}

.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.attach-menu-item:hover {
  background: var(--bg-hover);
}

.attach-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.attach-icon.bg-photo { background: #3498db; }
.attach-icon.bg-file { background: #e67e22; }
.attach-icon.bg-poll { background: #2ecc71; }

.attach-icon svg {
  width: 20px; height: 20px;
}

.emoji-item:active { transform: scale(0.9); }

/* ═══════════════════════════════════════════════════════
   USER PROFILE MODAL - REDESIGN
   ═══════════════════════════════════════════════════════ */

.profile-modal-content {
  background: var(--bg-modal);
  width: 100%;
  max-width: 420px;
  border-radius: 28px;
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  animation: profileModalIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  border: 1px solid var(--border-light);
}

@keyframes profileModalIn {
  from { opacity: 0; transform: scale(0.9) translateY(30px); filter: blur(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); filter: blur(0); }
}

.profile-modal-header {
  position: relative;
  height: 280px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 24px;
  color: #fff;
  background-size: cover;
  background-position: center;
  overflow: hidden;
}

.profile-modal-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.2) 0%, rgba(0,0,0,0.7) 100%);
  z-index: 1;
}

.profile-header-main {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 20px;
  animation: profileFadeUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.1s backwards;
}

@keyframes profileFadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

#profile-view-avatar {
  border: 4px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#profile-view-avatar:hover {
  transform: scale(1.05) rotate(3deg);
  border-color: #fff;
}

.profile-name-container h2 {
  font-size: 1.6rem;
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  margin-bottom: 4px;
}

.profile-modal-header .profile-status {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.8);
}

.profile-header-actions {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 3;
  display: flex;
  gap: 8px;
}

.profile-header-actions .icon-btn {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.profile-header-actions .icon-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px) scale(1.1);
}

#profile-modal-close {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 3;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.profile-modal-body {
  padding: 24px;
  background: var(--bg-modal);
  border-radius: 32px 32px 0 0;
  margin-top: -32px;
  position: relative;
  z-index: 2;
  box-shadow: 0 -12px 24px rgba(0,0,0,0.1);
}

.profile-info-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.profile-info-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px;
  border-radius: 16px;
  transition: all 0.3s ease;
  background: var(--bg-hover);
  border: 1px solid transparent;
}

.profile-info-item:hover {
  background: var(--bg-sidebar);
  border-color: var(--border-light);
  transform: translateX(4px);
  box-shadow: var(--shadow-sm);
}

.info-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--primary-bg);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.3s ease;
}

.profile-info-item:hover .info-icon {
  transform: scale(1.1) rotate(-5deg);
  background: var(--primary);
  color: #fff;
}

.info-icon svg { width: 22px; height: 22px; }

.info-content {
  flex: 1;
  min-width: 0;
}

.info-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-label {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.profile-tabs {
  display: flex;
  gap: 8px;
  background: var(--bg-hover);
  padding: 4px;
  border-radius: 14px;
  margin-bottom: 20px;
}

.profile-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 10px;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.profile-tab.active {
  background: var(--bg-modal);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.profile-tab:hover:not(.active) {
  color: var(--text-primary);
  background: rgba(0,0,0,0.02);
}

.profile-actions .btn {
  height: 52px;
  border-radius: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.bio-variations-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.bio-var-group {
  margin-bottom: 0 !important;
  position: relative;
}

.bio-var-group::before {
  content: counter(bio-counter);
  counter-increment: bio-counter;
  position: absolute;
  left: 12px;
  top: 16px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-tertiary);
  pointer-events: none;
  z-index: 1;
}

.bio-variations-list {
  counter-reset: bio-counter;
}

.bio-variation-input {
  font-size: 0.95rem !important;
  padding: 14px 14px 14px 34px !important;
  border-radius: 12px !important;
  background: var(--bg-hover) !important;
  border: 1px solid transparent !important;
  color: var(--text-primary) !important;
  transition: all 0.3s ease !important;
}

.bio-variation-input:focus {
  background: var(--bg-input) !important;
  border-color: var(--primary) !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05), 0 0 0 3px var(--primary-bg) !important;
  transform: translateY(-1px);
}

.avatar-color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.avatar-color-option {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
}

.avatar-color-option:hover { transform: scale(1.15); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }

.avatar-color-option.selected {
  border-color: var(--bg-modal);
  box-shadow: 0 0 0 2px var(--primary), 0 4px 12px var(--primary-glow);
  transform: scale(1.1);
}

/* Mobile Responsiveness for Settings Modal */
@media (max-width: 768px) {
  #settings-modal .modal {
    max-width: 100%;
    width: 100%;
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
  }
  
  #settings-modal .settings-body {
    flex: 1;
    overflow-y: auto;
  }

  #settings-modal .settings-profile-header {
    padding-top: calc(24px + env(safe-area-inset-top, 0px));
  }
  
  .avatar-color-grid {
    grid-template-columns: repeat(8, 1fr);
    gap: 8px;
  }
  
  .avatar-color-option {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
  }
}

/* ═══════════════════════════════════════════════════════
   USER PROFILE MODAL - REDESIGN END
   ═══════════════════════════════════════════════════════ */

.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  padding: 20px;
  animation: overlayFadeIn 0.25s ease;
}

@keyframes overlayFadeIn {
  from { opacity: 0; backdrop-filter: blur(0); }
  to { opacity: 1; backdrop-filter: blur(4px); }
}

[data-theme="dark"] .modal-overlay { background: rgba(0, 0, 0, 0.8); }

.modal {
  width: 100%;
  max-width: 440px;
  max-height: 80vh;
  background: var(--bg-modal);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalSpring 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalSpring {
  from { opacity: 0; transform: scale(0.85) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 1.15rem; font-weight: 600; }

.modal-close {
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-close:hover { transform: rotate(90deg) scale(1.1); }
.modal-close svg { width: 18px; height: 18px; }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ─── Modal Search ───────────────────────────────────── */
.modal-search {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.modal-search .search-icon {
  position: absolute;
  left: 14px;
  width: 18px; height: 18px;
  color: var(--text-tertiary);
  pointer-events: none;
  transition: color 0.3s ease;
  z-index: 1;
}

.modal-search .search-input {
  width: 100%;
  padding: 12px 14px 12px 44px;
  background: var(--bg-hover);
  border: 1.5px solid transparent;
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-search .search-input:focus {
  background: var(--bg-input);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-bg);
}

.modal-search .search-input:focus + .search-icon,
.modal-search .search-input:focus ~ .search-icon {
  color: var(--primary);
}

/* ─── User Search Results ──────────────────────────── */
.user-search-results {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 300px;
  overflow-y: auto;
}

.user-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  animation: resultSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.user-result:nth-child(1) { animation-delay: 0.02s; }
.user-result:nth-child(2) { animation-delay: 0.06s; }
.user-result:nth-child(3) { animation-delay: 0.10s; }
.user-result:nth-child(4) { animation-delay: 0.14s; }

@keyframes resultSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.user-result:hover {
  background: var(--bg-hover);
  transform: translateX(4px);
}

.user-result:active { transform: scale(0.98); }

.user-result-info { flex: 1; min-width: 0; }
.user-result-name { font-weight: 500; font-size: 0.92rem; }
.user-result-username { font-size: 0.8rem; color: var(--text-tertiary); }

/* ─── Settings ─────────────────────────────────────── */
.settings-header { justify-content: space-between; }
.settings-header .save-btn { color: #2ecc71; }

.settings-body {
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-modal);
  padding: 32px 20px 24px;
}

.settings-avatar-wrapper {
  position: relative;
  width: 96px; height: 96px;
  margin-bottom: 16px;
  cursor: pointer;
  border-radius: 50%;
  box-shadow: var(--shadow-md);
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.settings-avatar-wrapper:hover {
  transform: scale(1.08);
  box-shadow: var(--shadow-lg), 0 0 20px var(--primary-glow);
}

.settings-avatar-large {
  width: 100%; height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  color: #fff;
  font-weight: 600;
  overflow: hidden;
}

.settings-avatar-large img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.settings-avatar-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  opacity: 0;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(2px);
}

.settings-avatar-wrapper:hover .settings-avatar-overlay { opacity: 1; }
.settings-avatar-overlay svg { width: 32px; height: 32px; }

.settings-main-name { font-size: 1.3rem; font-weight: 600; margin-bottom: 4px; }
.settings-status { font-size: 0.9rem; color: #2ecc71; }

.settings-section {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: var(--bg-modal);
}

.form-label-static {
  display: block;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.avatar-color-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.avatar-color-option {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.avatar-color-option:hover { transform: scale(1.2); }

.avatar-color-option.selected {
  border-color: var(--text-primary);
  transform: scale(1.15);
  box-shadow: 0 0 12px var(--primary-glow);
}

/* ─── Selected Members ─────────────────────────────── */
.selected-members {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.selected-member {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 6px;
  background: var(--primary-bg);
  border-radius: 20px;
  font-size: 0.82rem;
  color: var(--primary);
  cursor: pointer;
  animation: memberPop 0.3s var(--transition-bounce);
  transition: all 0.2s ease;
}

@keyframes memberPop {
  from { opacity: 0; transform: scale(0); }
  to { opacity: 1; transform: scale(1); }
}

.selected-member:hover {
  background: var(--primary-bg-hover);
  transform: scale(1.05);
}

.selected-member .avatar {
  width: 22px; height: 22px;
  font-size: 0.55rem;
}

/* ═══════════════════════════════════════════════════════
   CONTEXT MENU
   ═══════════════════════════════════════════════════════ */

.context-menu {
  position: fixed;
  min-width: 180px;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  padding: 6px;
  z-index: var(--z-context);
  animation: contextMenuIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  backdrop-filter: blur(12px);
}

@keyframes contextMenuIn {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

.context-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font-size: 0.86rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
}

.context-item:hover {
  background: var(--bg-hover);
  padding-left: 18px;
}

.context-item:active { transform: scale(0.97); }

.context-item svg {
  width: 18px; height: 18px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.context-item:hover svg { color: var(--primary); }
.context-item-danger { color: var(--text-danger); }
.context-item-danger svg { color: var(--text-danger); }
.context-item-danger:hover svg { color: var(--text-danger); }

/* No results */
.no-results {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 150px;
  padding: 24px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.88rem;
  animation: noResultsFade 0.5s ease;
}

@keyframes noResultsFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ═══════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ═══════════════════════════════════════════════════════ */

.toast-notification {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(30px);
  padding: 12px 24px;
  border-radius: 16px;
  font-size: 0.88rem;
  font-weight: 500;
  color: #fff;
  z-index: var(--z-toast);
  opacity: 0;
  pointer-events: none;
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toast-notification.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-info { background: rgba(51, 144, 236, 0.92); }
.toast-success { background: rgba(46, 204, 113, 0.92); }
.toast-error { background: rgba(229, 57, 53, 0.92); }

/* ═══════════════════════════════════════════════════════
   USER PROFILE MODAL — REDESIGNED
   ═══════════════════════════════════════════════════════ */

.profile-modal-content {
  width: 100%;
  max-width: 440px;
  padding: 0 !important;
  overflow: hidden;
  border-radius: 32px;
  background: var(--bg-modal);
  box-shadow: 0 40px 100px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  animation: profileModalIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  max-height: 90vh;
  position: relative;
}

@keyframes profileModalIn {
  from { opacity: 0; transform: scale(0.9) translateY(50px); filter: blur(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); filter: blur(0); }
}

/* ─── Profile Header (User & Group shared) ─── */
.profile-modal-header, .profile-header {
  position: relative;
  background: linear-gradient(135deg, rgba(255,255,255,0.05), transparent), var(--bg-overlay);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--text-primary);
  padding: 80px 24px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  border-bottom: 1px solid var(--border-light);
  overflow: hidden;
}

.profile-modal-header::before, .profile-header::before {
  content: '';
  position: absolute;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background: radial-gradient(circle at 50% 0%, var(--primary-glow) 0%, transparent 50%);
  opacity: 0.3;
  pointer-events: none;
  animation: pulseGlow 10s ease-in-out infinite alternate;
}

@keyframes pulseGlow {
  0% { transform: scale(1); opacity: 0.2; }
  100% { transform: scale(1.1); opacity: 0.4; }
}

/* ─── Header nav buttons ─── */
.profile-header-actions, #profile-modal-close, .profile-back-btn {
  position: absolute;
  top: 20px;
  z-index: 10;
}

.profile-header-actions { right: 20px; display: flex; gap: 8px; }
#profile-modal-close, .profile-back-btn { left: 20px; }

.profile-header-actions .icon-btn, #profile-modal-close, .profile-back-btn {
  color: var(--text-primary) !important;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 42px; height: 42px;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.profile-header-actions .icon-btn:hover, #profile-modal-close:hover, .profile-back-btn:hover {
  background: var(--bg-sidebar);
  border-color: var(--primary);
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* ─── Avatar in header ─── */
.profile-header-main, #group-profile-avatar {
  position: relative;
  z-index: 2;
  margin-bottom: 16px;
}

#profile-view-avatar, #group-profile-avatar {
  border: 4px solid var(--bg-modal);
  box-shadow: 0 12px 32px rgba(0,0,0,0.2);
  border-radius: 35%; /* Squircle shape */
  transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  width: 120px !important;
  height: 120px !important;
  font-size: 3rem !important;
  margin: 0 auto;
}

#profile-view-avatar:hover, #group-profile-avatar:hover {
  transform: scale(1.08) rotate(4deg);
  border-radius: 50%;
}

.profile-name-container h2, #group-profile-name {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
  background: linear-gradient(to right, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.profile-modal-header .profile-status, #group-profile-status {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 4px 12px;
  background: var(--bg-hover);
  border-radius: 20px;
  display: inline-block;
  border: 1px solid var(--border-light);
}

.profile-modal-header .profile-status.online, #group-profile-status.online {
  color: var(--success);
  background: rgba(46, 204, 113, 0.1);
  border-color: rgba(46, 204, 113, 0.2);
}

/* ─── Profile Body ─── */
.profile-modal-body, .profile-body {
  padding: 24px;
  background: var(--bg-modal);
  flex: 1;
  overflow-y: auto;
}

/* Scrollbar for profile body */
.profile-modal-body::-webkit-scrollbar { width: 6px; }
.profile-modal-body::-webkit-scrollbar-track { background: transparent; }
.profile-modal-body::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 10px; }

.profile-info-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 28px;
}

.profile-info-item, .profile-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: var(--bg-hover);
  border-radius: 20px;
  border: 1px solid var(--border-light);
  transition: all 0.3s ease;
}

.profile-info-item:hover, .profile-item:hover {
  background: var(--bg-sidebar);
  border-color: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.info-icon, .profile-item-icon {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: var(--primary-bg);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.profile-info-item:hover .info-icon, .profile-item:hover .profile-item-icon {
  background: var(--primary);
  color: #fff;
  transform: scale(1.1) rotate(-8deg);
  border-radius: 50%;
}

.info-icon svg, .profile-item-icon svg { width: 24px; height: 24px; }

.info-content, .profile-item-content {
  flex: 1;
  min-width: 0;
}

.info-value, .profile-item-value {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.4;
}

.info-label, .profile-item-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-tertiary);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Tabs */
.profile-tabs {
  display: flex;
  gap: 8px;
  background: var(--bg-hover);
  padding: 6px;
  border-radius: 16px;
  margin-bottom: 24px;
  border: 1px solid var(--border-light);
}

.profile-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 12px;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.profile-tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.profile-tab:hover:not(.active) {
  background: var(--bg-sidebar);
  color: var(--text-primary);
}

/* Actions */
.profile-actions .btn {
  height: 56px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  box-shadow: 0 8px 24px var(--primary-glow);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.profile-actions .btn:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 12px 32px var(--primary-glow);
}

/* ═══════════════════════════════════════════════════════ */
  z-index: 1;
}

.profile-header-main .avatar {
  width: 110px;
  height: 110px;
  font-size: 2.8rem;
  border: 4px solid rgba(255,255,255,0.35);
  box-shadow: 0 8px 40px rgba(0,0,0,0.35), 0 0 0 2px rgba(255,255,255,0.1);
  animation: profileAvatarIn 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) 0.05s backwards;
}

@keyframes profileAvatarIn {
  from { opacity: 0; transform: scale(0.4) rotate(-10deg); }
  to { opacity: 1; transform: scale(1) rotate(0deg); }
}

.profile-name-container h2 {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  text-shadow: 0 2px 16px rgba(0,0,0,0.25);
  animation: profileTextIn 0.4s ease 0.15s backwards;
}

@keyframes profileTextIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.profile-status {
  font-size: 0.88rem;
  color: rgba(255,255,255,0.75);
  font-weight: 400;
  animation: profileTextIn 0.4s ease 0.22s backwards;
}

.profile-status.online {
  color: #7dffb3;
  font-weight: 600;
  text-shadow: 0 0 12px rgba(125, 255, 179, 0.5);
}

/* ─── Body ─── */
.profile-modal-body {
  overflow-y: auto;
  flex: 1;
}

.profile-info-list {
  padding: 8px 0 4px;
}

.profile-info-item {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 14px 20px;
  margin: 3px 12px;
  border-radius: 14px;
  background: var(--bg-input);
  cursor: pointer;
  transition: all 0.2s ease;
}

.profile-info-item:hover {
  background: var(--bg-hover);
  transform: translateX(3px);
}

@keyframes profileItemSlide {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

.info-icon {
  width: 20px; height: 20px;
  color: var(--primary);
  flex-shrink: 0;
  margin-top: 3px;
}

.info-icon svg { width: 100%; height: 100%; }

.info-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 2px;
}

.info-value {
  font-size: 0.95rem;
  color: var(--text-primary);
  font-weight: 500;
  word-break: break-word;
}

.info-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* ─── Divider between info & actions ─── */
.profile-divider {
  height: 1px;
  background: var(--border-light);
  margin: 4px 12px 4px;
}

/* ─── Action buttons (notifications, media, block) ─── */
.profile-settings-list { padding: 6px 0 2px; }

.profile-setting-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  margin: 3px 12px;
  border-radius: 14px;
  background: var(--bg-input);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
  transition: all 0.2s ease;
}

.profile-setting-item:hover {
  background: var(--bg-hover);
  transform: translateX(3px);
}

.profile-setting-item.item-danger { color: var(--text-danger); }
.profile-setting-item.item-danger .info-icon { color: var(--text-danger); }

/* ─── Send message button ─── */
.profile-actions {
  padding: 10px 16px 20px;
}

.btn-primary.full-width {
  width: 100%;
  padding: 14px 24px;
  border-radius: 14px;
  font-size: 0.95rem;
  gap: 10px;
}

/* ─── Profile list (members in group) ─── */
.profile-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 8px;
}

.profile-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.2s;
  border-radius: 14px;
  margin: 0 4px;
}

.profile-list-item:hover {
  background: var(--bg-hover);
}

.profile-list-info {
  flex: 1;
  min-width: 0;
}

.profile-list-name {
  font-weight: 500;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-list-status {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  :root {
    --header-height: calc(56px + env(safe-area-inset-top, 0px));
    --input-height: 52px;
    --sidebar-width: 100%;
  }

  body, .messenger, .sidebar, .chat-area {
    height: 100%; height: 100dvh;
    overflow: hidden;
  }

  .sidebar {
    position: absolute;
    width: 100%; min-width: 100%;
    z-index: 20;
    border-right: none;
  }

  .chat-area { 
    width: 100%; 
    display: none; 
  }

  .messenger.chat-open .chat-area {
    display: flex;
  }

  .messenger.chat-open .sidebar {
    display: none;
  }

  .chat-header {
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    padding-bottom: 10px;
    gap: 10px;
  }

  .message-input-area {
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
  }

  .input-wrapper {
    gap: 6px;
  }

  .input-inner {
    padding: 5px 8px 5px 4px;
    gap: 0px;
  }

  #message-input {
    font-size: 0.93rem;
    padding: 6px 0px;
    margin: 0 6px;
  }

  .send-btn, .voice-btn {
    width: 38px; height: 38px;
    min-width: 38px;
  }

  .send-btn svg, .voice-btn svg {
    width: 18px; height: 18px;
  }

  .input-inner .icon-btn {
    width: 30px; height: 30px;
    min-width: 30px;
    min-height: 30px;
  }

  .input-inner .icon-btn svg {
    width: 18px; height: 18px;
  }

  .sidebar-header {
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
  }

  .back-btn { display: flex; }

  .messages-list { padding: 0 8px; }
  .reply-preview { margin: 0 8px; }
  .message { max-width: 88%; }

  .emoji-picker {
    left: 8px; right: 8px;
    width: auto;
    bottom: calc(var(--input-height) + env(safe-area-inset-bottom, 0px) + 8px);
  }

  .attach-menu {
    left: 8px; right: 8px;
    width: auto;
    bottom: calc(var(--input-height) + env(safe-area-inset-bottom, 0px) + 8px);
    border-radius: var(--radius-lg);
  }

  .attach-menu-item {
    padding: 14px 18px;
  }

  .modal-overlay {
    padding: 0;
  }

  .profile-modal-content, .modal, #new-contact-modal, #new-contact-overlay {
    max-width: 100%;
    width: 100%;
    height: 100%; height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    padding: 0;
    animation: profileModalMobileIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1000;
  }

  @keyframes profileModalMobileIn {
    from { opacity: 0; transform: translateY(100%); }
    to { opacity: 1; transform: translateY(0); }
  }

  .profile-header-main .avatar {
    width: 100px; height: 100px;
  }

  .fab-btn {
    bottom: 16px; right: 16px;
    width: 52px; height: 52px;
  }

  /* Chat header info tap area */
  .chat-header-info {
    min-height: 44px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  /* Better touch targets for icon buttons */
  .icon-btn {
    min-width: 44px;
    min-height: 44px;
  }

  /* Search bar compact on mobile */
  .chat-search-bar {
    padding: 6px 10px;
  }

  .chat-search-inner {
    border-radius: 8px;
  }

  /* Dropdown menu full-width on mobile */
  .dropdown-menu, .sidebar-menu {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 70vh;
    overflow-y: auto;
    padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px));
    animation: bottomSheetIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
    transform-origin: bottom center;
    z-index: 1001;
    border: none;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
  }

  .dropdown-menu::before, .sidebar-menu::before, .context-menu::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 4px;
    margin: 0 auto 12px;
  }

  @keyframes bottomSheetIn {
    from { opacity: 0; transform: translateY(100%); }
    to { opacity: 1; transform: translateY(0); }
  }

  .dropdown-menu .menu-item, .sidebar-menu .menu-item {
    padding: 16px 20px;
    font-size: 1rem;
  }

  /* Context menu mobile */
  .context-menu {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    animation: bottomSheetIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .context-item {
    padding: 16px 20px;
    font-size: 1rem;
  }

  /* Profile list on mobile */
  .profile-list-item {
    padding: 12px 16px;
  }

  /* Group profile mobile */
  .profile-avatar-large .group-avatar {
    width: 80px;
    height: 80px;
  }

  .profile-header .group-avatar svg {
    width: 32px;
    height: 32px;
  }
}

@media (max-width: 480px) {
  .auth-container {
    padding: 28px 20px;
    border-radius: 16px;
    max-width: 95%;
  }

  .auth-title { font-size: 1.6rem; }
  .message-bubble { padding: 6px 10px 8px; }
  .message { max-width: 92%; }

  .chat-header {
    padding: 8px 10px;
    gap: 8px;
  }

  .chat-header-avatar .avatar {
    width: 36px; height: 36px;
    font-size: 0.85rem;
  }

  .chat-header-avatar .saved-icon {
    width: 36px !important; height: 36px !important;
  }

  .chat-header-avatar .group-avatar {
    width: 36px; height: 36px;
  }

  .chat-header-avatar .group-avatar svg {
    width: 18px; height: 18px;
  }

  .chat-header-name { font-size: 0.95rem; }
  .chat-header-status { font-size: 0.73rem; }

  .chat-header-actions .icon-btn {
    min-width: 38px;
    min-height: 38px;
  }

  .message-input-area {
    padding: 3px 4px calc(3px + env(safe-area-inset-bottom, 0px));
  }

  .input-inner {
    padding: 4px 6px 4px 2px;
    gap: 0px;
  }

  #message-input {
    font-size: 0.9rem;
    padding: 5px 0px;
    margin: 0 4px;
  }

  .send-btn, .voice-btn {
    width: 36px; height: 36px;
    min-width: 36px;
  }

  .messages-list { padding: 0 6px; }
  .reply-preview { margin: 0 6px; }

  .fab-btn {
    bottom: 12px; right: 12px;
    width: 48px; height: 48px;
  }

  .fab-btn svg { width: 22px; height: 22px; }

  .sidebar-header {
    padding: 8px 6px 8px 10px;
  }

  .search-input {
    padding: 8px 10px 8px 36px;
    font-size: 0.86rem;
  }

  .chat-item {
    padding: 8px 10px;
    gap: 10px;
  }

  .chat-item-name { font-size: 0.9rem; }
  .chat-item-preview { font-size: 0.82rem; }
  .chat-item-time { font-size: 0.7rem; }
}

@media (max-width: 360px) {
  .message { max-width: 95%; }
  .message-bubble { padding: 5px 8px 7px; }
  .message-text { font-size: 0.88rem; }
  .messages-list { padding: 0 4px; }

  .chat-header {
    padding: 6px 8px;
    gap: 6px;
  }

  .chat-header-avatar .avatar {
    width: 32px; height: 32px;
    font-size: 0.8rem;
  }

  .chat-header-name { font-size: 0.9rem; }
}

/* ─── New Contact Modal Refinement ─────────────────── */
#new-contact-modal {
  border-radius: 24px;
  background-color: var(--bg-modal);
  color: var(--text-primary);
  max-width: 420px;
  box-shadow: var(--shadow-xl);
}

[data-theme="dark"] #new-contact-modal {
  background-color: #1c1c1c;
}

#new-contact-modal .modal-header {
  border-bottom: none;
  padding-bottom: 0;
}

#new-contact-modal .modal-title {
  font-size: 1.35rem;
  font-weight: 700;
  padding: 24px 24px 0;
}

#new-contact-modal .modal-body {
  padding: 20px 24px 24px;
}

.contact-header-info {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 28px;
}

.contact-header-text {
  flex: 1;
  min-width: 0;
}

#contact-name {
  font-size: 1.25rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

#contact-status {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.contact-notes-area {
  resize: none;
  height: 80px;
}

.contact-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.45;
}

.contact-share-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  margin-top: 20px;
  padding: 12px;
  background: var(--bg-hover);
  border-radius: 12px;
  transition: background 0.2s ease;
}

.contact-share-option:hover {
  background: var(--bg-active);
}

.contact-share-option input[type="checkbox"] {
  margin-top: 2px;
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.contact-share-option .contact-hint {
  margin-bottom: 0;
}

.share-option-title {
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px 24px;
}

#new-contact-modal .form-group {
  position: relative;
  margin-bottom: 24px;
}

#new-contact-modal .form-input {
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  color: var(--text-primary);
  font-size: 1rem;
  transition: all 0.3s ease;
  width: 100%;
}

[data-theme="dark"] #new-contact-modal .form-input {
  border-color: #3d3d3d;
}

#new-contact-modal .form-input:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 4px var(--primary-bg);
}

#new-contact-modal .form-label {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  font-size: 1rem;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  background: var(--bg-modal);
  padding: 0 4px;
  margin-left: -4px; /* Offset padding */
}

/* Adjust textarea label to top-align correctly */
#new-contact-modal textarea.form-input ~ .form-label {
  top: 24px;
}

[data-theme="dark"] #new-contact-modal .form-label {
  background: #1c1c1c;
}

#new-contact-modal .form-input:focus ~ .form-label,
#new-contact-modal .form-input:not(:placeholder-shown) ~ .form-label {
  top: 0;
  transform: translateY(-50%) scale(0.85);
  transform-origin: left center;
  color: var(--primary);
}

#new-contact-modal .btn-text {
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 12px 24px;
  border-radius: 12px;
  background: transparent;
  color: var(--primary);
  min-width: auto;
  transition: all 0.2s ease;
}

#new-contact-modal .btn-text:hover {
  background: var(--primary-bg);
}

#new-contact-modal #contact-done-btn {
  background: var(--primary);
  color: #fff !important;
}

#new-contact-modal #contact-done-btn:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px var(--primary-glow);
}

#new-channel-modal .modal-body {
  padding-top: 24px;
}

#new-channel-modal #channel-desc-input {
  min-height: 100px;
}

#contact-avatar {
  border: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

#contact-share-phone {
  accent-color: var(--primary);
  width: 20px;
  height: 20px;
}

/* ═══════════════════════════════════════════════════════
   SELECTION & FOCUS STYLES
   ═══════════════════════════════════════════════════════ */

::selection {
  background: var(--primary-bg);
  color: var(--text-primary);
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ═══════════════════════════════════════════════════════
   LOADING SKELETON  
   ═══════════════════════════════════════════════════════ */

.skeleton {
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--border) 50%, var(--bg-hover) 75%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeletonShimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ═══════════════════════════════════════════════════════
   JS-TRIGGERED ANIMATION KEYFRAMES
   ═══════════════════════════════════════════════════════ */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes overlayFadeOut {
  from { opacity: 1; backdrop-filter: blur(4px); }
  to { opacity: 0; backdrop-filter: blur(0); }
}

@keyframes modalOut {
  from { opacity: 1; transform: scale(1) translateY(0); }
  to { opacity: 0; transform: scale(0.9) translateY(10px); }
}

@keyframes contextMenuOut {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.85); }
}

/* ─── Typing Dots Inline ───────────────────────────── */
.typing-dots-inline {
  display: inline-flex;
  margin-left: 1px;
}

.typing-dots-inline span {
  animation: typingBounce 1.4s ease-in-out infinite;
  font-weight: 700;
}

.typing-dots-inline span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots-inline span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

/* ─── Muted Icon ──────────────────────────────────── */
.muted-icon {
  display: inline-block;
  vertical-align: middle;
  opacity: 0.5;
  margin-left: 4px;
}

/* ═══════════════════════════════════════════════════════
   ENHANCED INTERACTION ANIMATIONS
   ═══════════════════════════════════════════════════════ */

/* Send button pop on message send */
@keyframes sendPop {
  0% { transform: scale(1); }
  30% { transform: scale(0.8) rotate(-8deg); }
  60% { transform: scale(1.2) rotate(4deg); }
  100% { transform: scale(1) rotate(0); }
}

/* Voice button pulse effect */
@keyframes voicePulse {
  0% { transform: scale(1); box-shadow: 0 2px 8px var(--primary-glow); }
  25% { transform: scale(1.15); box-shadow: 0 0 0 8px rgba(108, 92, 231, 0.2), 0 2px 8px var(--primary-glow); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.1), 0 2px 8px var(--primary-glow); }
  75% { transform: scale(1.12); box-shadow: 0 0 0 6px rgba(108, 92, 231, 0.15), 0 2px 8px var(--primary-glow); }
  100% { transform: scale(1); box-shadow: 0 2px 8px var(--primary-glow); }
}

/* Button swap crossfade */
@keyframes btnSwapIn {
  0% { opacity: 0; transform: scale(0.5) rotate(-30deg); }
  60% { opacity: 1; transform: scale(1.1) rotate(5deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

/* FAB spin when opening new chat */
@keyframes fabSpin {
  0% { transform: scale(1) rotate(0); }
  50% { transform: scale(0.9) rotate(180deg); }
  100% { transform: scale(1) rotate(360deg); }
}

/* Chat area slide out on back button (mobile) */
@keyframes chatSlideOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(30px); }
}

/* Auth form cross-fade transitions */
@keyframes authFormOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-12px) scale(0.96); }
}

@keyframes authFormIn {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Scroll-to-bottom button click feedback */
@keyframes scrollBtnClick {
  0% { transform: scale(1); }
  40% { transform: scale(0.85) translateY(3px); }
  70% { transform: scale(1.08) translateY(-2px); }
  100% { transform: scale(1) translateY(0); }
}

/* Search focus pulse (Ctrl+K) */
@keyframes searchFocusPulse {
  0% { box-shadow: none; }
  40% { box-shadow: 0 0 0 4px var(--primary-bg), 0 0 16px var(--primary-glow); }
  100% { box-shadow: none; }
}

/* Scroll-to-bottom pulse for unread messages */
.scroll-bottom-btn:not(.hidden) .unread-badge:not(.hidden) ~ * {
  animation: none;
}

.scroll-bottom-btn.has-unread {
  animation: scrollUnreadPulse 2s ease-in-out infinite;
}

@keyframes scrollUnreadPulse {
  0%, 100% { box-shadow: var(--shadow-lg); }
  50% { box-shadow: var(--shadow-lg), 0 0 0 4px rgba(229, 57, 53, 0.2); }
}

/* Profile header gradient animation (combined with modal open) */
.profile-modal-header {
  background-size: 200% 200%;
  animation: profileModalIn 0.45s cubic-bezier(0.16, 1, 0.3, 1), profileGradientShift 8s ease 0.5s infinite;
}

@keyframes profileGradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* Enhanced context menu glass effect for dark theme */
[data-theme="dark"] .context-menu {
  background: rgba(23, 33, 43, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* Enhanced emoji item hover wave */
.emoji-item:hover {
  background: var(--bg-hover);
  transform: scale(1.3);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}

/* Context menu items cascade animation */
.context-menu .context-item {
  animation: menuItemCascade 0.2s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}
.context-menu .context-item:nth-child(1) { animation-delay: 0.02s; }
.context-menu .context-item:nth-child(2) { animation-delay: 0.04s; }
.context-menu .context-item:nth-child(3) { animation-delay: 0.06s; }
.context-menu .context-item:nth-child(4) { animation-delay: 0.08s; }
.context-menu .context-item:nth-child(5) { animation-delay: 0.10s; }
.context-menu .context-item:nth-child(6) { animation-delay: 0.12s; }
.context-menu .context-item:nth-child(7) { animation-delay: 0.14s; }

/* Dropdown menu — no cascade animation delay (prevented items from showing on re-open) */

/* Three-dots button active state (morph to X) */
.chat-menu-btn-active svg {
  transform: rotate(90deg);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#chat-menu-btn svg {
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Dropdown menu item hover improvement */
.dropdown-menu .menu-item:hover {
  background: var(--bg-active);
  padding-left: 18px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Enhanced input wrapper focus glow */
.input-inner:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg), 0 0 16px var(--primary-glow);
  transform: translateY(-1px);
}

/* Improved message hover effects */
.message-bubble:active {
  filter: brightness(0.94);
  transform: scale(0.99);
}

/* Settings save button success animation */
.save-btn.loading svg {
  animation: spin 0.6s linear infinite;
}

.save-btn:not(.loading):active svg {
  animation: checkBounce 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes checkBounce {
  0% { transform: scale(1); }
  40% { transform: scale(0.8); }
  70% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* User result hover enhancement */
.user-result:hover .avatar {
  transform: scale(1.1);
  box-shadow: 0 2px 8px var(--primary-glow);
}

/* Toast notification icon enhancement */
.toast-notification::before {
  display: inline-block;
  margin-right: 8px;
  font-size: 1.1em;
}

.toast-success::before { content: '✓'; }
.toast-error::before { content: '✕'; }
.toast-info::before { content: 'ℹ'; }

/* ─── Profile Enhancements ────────────────────────── */
.profile-avatar-large {
  width: 100px;
  height: 100px;
  font-size: 2.5rem;
  border: 4px solid rgba(255,255,255,0.2);
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  background: var(--primary-light);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  margin: 0 auto;
}

.profile-name {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  margin-top: 12px;
}

.profile-status {
  font-size: 0.95rem;
  opacity: 0.9;
  color: #fff;
}

.profile-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  background: var(--bg-modal);
}

.profile-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--primary);
  margin-bottom: 4px;
}

.profile-item {
  display: flex;
  align-items: center;
  gap: 16px;
}

.profile-item-icon {
  width: 24px;
  height: 24px;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-item-content {
  flex: 1;
}

.profile-item-value {
  font-size: 1rem;
  color: var(--text-main);
  margin-bottom: 2px;
}

.profile-item-label {
  font-size: 0.8rem;
  color: var(--text-tertiary);
}



.profile-tab-panels {
  position: relative;
  min-height: 200px;
}

.profile-panel {
  display: none;
  padding: 12px;
}

.profile-panel.active {
  display: block;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
}

.media-grid .no-results {
  grid-column: 1 / -1;
}

.media-item {
  aspect-ratio: 1;
  background: var(--bg-input);
  cursor: pointer;
  overflow: hidden;
}

.media-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.files-list {
  display: flex;
  flex-direction: column;
}

.no-results {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 150px;
  padding: 40px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Modal Mobile Responsiveness Fix */
@media (max-width: 768px) {
  #new-contact-modal {
    max-width: 100%;
    width: 100%;
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
  }
  
  #new-contact-modal .modal-body {
    flex: 1;
    overflow-y: auto;
  }
  
  #new-contact-modal .modal-header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 16px;
  }
}


 . m e s s a g e - e 2 e e   { 
     d i s p l a y :   i n l i n e - f l e x ; 
     a l i g n - i t e m s :   c e n t e r ; 
     c o l o r :   v a r ( - - p r i m a r y ) ; 
     m a r g i n - r i g h t :   2 p x ; 
 } 
 . m e s s a g e - e 2 e e   s v g   { 
     w i d t h :   1 4 p x ; 
     h e i g h t :   1 4 p x ; 
 } 
  
 