/* ─── 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 {
    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);
  }

  .sidebar-menu::before { display: none !important; }

  @keyframes bottomSheetIn {
    from { opacity: 0; transform: translateY(100%); }
    to { opacity: 1; transform: translateY(0); }
  }

  .dropdown-menu .menu-item, .sidebar-menu .menu-item {
    padding: 14px 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); }
}

/* ─── 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 ; 
 } 
  
 
 . s e t t i n g s - m o d a l - c o n t a i n e r   { 
     m a x - w i d t h :   8 0 0 p x ; 
     d i s p l a y :   f l e x ; 
     f l e x - d i r e c t i o n :   r o w ; 
     p a d d i n g :   0 ; 
     o v e r f l o w :   h i d d e n ; 
     h e i g h t :   8 0 v h ; 
 } 
 . s e t t i n g s - s i d e b a r   { 
     w i d t h :   2 5 0 p x ; 
     b a c k g r o u n d :   v a r ( - - b g - s i d e b a r ) ; 
     b o r d e r - r i g h t :   1 p x   s o l i d   v a r ( - - b o r d e r ) ; 
     d i s p l a y :   f l e x ; 
     f l e x - d i r e c t i o n :   c o l u m n ; 
 } 
 . s e t t i n g s - s i d e b a r - h e a d e r   { 
     p a d d i n g :   2 0 p x ; 
     f o n t - w e i g h t :   b o l d ; 
     f o n t - s i z e :   1 . 2 r e m ; 
     b o r d e r - b o t t o m :   1 p x   s o l i d   v a r ( - - b o r d e r ) ; 
 } 
 . s e t t i n g s - t a b s - s c r o l l   { 
     f l e x :   1 ; 
     o v e r f l o w - y :   a u t o ; 
 } 
 . s e t t i n g s - t a b - b t n   { 
     w i d t h :   1 0 0 % ; 
     p a d d i n g :   1 5 p x   2 0 p x ; 
     t e x t - a l i g n :   l e f t ; 
     b a c k g r o u n d :   t r a n s p a r e n t ; 
     b o r d e r :   n o n e ; 
     c o l o r :   v a r ( - - t e x t - s e c o n d a r y ) ; 
     c u r s o r :   p o i n t e r ; 
     b o r d e r - l e f t :   3 p x   s o l i d   t r a n s p a r e n t ; 
     t r a n s i t i o n :   a l l   0 . 2 s   e a s e ; 
     f o n t - s i z e :   1 r e m ; 
 } 
 . s e t t i n g s - t a b - b t n . a c t i v e   { 
     c o l o r :   v a r ( - - t e x t - p r i m a r y ) ; 
     b o r d e r - l e f t :   3 p x   s o l i d   v a r ( - - p r i m a r y ) ; 
     b a c k g r o u n d :   v a r ( - - b g - h o v e r ) ; 
 } 
 . s e t t i n g s - c o n t e n t   { 
     f l e x :   1 ; 
     d i s p l a y :   f l e x ; 
     f l e x - d i r e c t i o n :   c o l u m n ; 
     b a c k g r o u n d :   v a r ( - - b g - m o d a l ) ; 
     p o s i t i o n :   r e l a t i v e ; 
     o v e r f l o w :   h i d d e n ; 
 } 
 . s e t t i n g s - h e a d e r - a c t i o n s   { 
     d i s p l a y :   f l e x ; 
     g a p :   1 0 p x ; 
 } 
 . s e t t i n g s - t a b - c o n t e n t   { 
     a n i m a t i o n :   f a d e I n   0 . 3 s   e a s e ; 
 } 
 
 @ m e d i a   ( m a x - w i d t h :   7 6 8 p x )   { 
     . s e t t i n g s - m o d a l - c o n t a i n e r   { 
         f l e x - d i r e c t i o n :   c o l u m n ; 
         h e i g h t :   1 0 0 % ; 
         w i d t h :   1 0 0 % ; 
         m a x - w i d t h :   1 0 0 % ; 
         b o r d e r - r a d i u s :   0 ; 
     } 
     . s e t t i n g s - s i d e b a r   { 
         w i d t h :   1 0 0 % ; 
         b o r d e r - r i g h t :   n o n e ; 
         b o r d e r - b o t t o m :   1 p x   s o l i d   v a r ( - - b o r d e r ) ; 
     } 
     . s e t t i n g s - s i d e b a r - h e a d e r   { 
         d i s p l a y :   n o n e ;   / *   H i d e   h e a d e r   o n   m o b i l e ,   s a v e   s p a c e   * / 
     } 
     . s e t t i n g s - t a b s - s c r o l l   { 
         d i s p l a y :   f l e x ; 
         f l e x - d i r e c t i o n :   r o w ; 
         o v e r f l o w - x :   a u t o ; 
         o v e r f l o w - y :   h i d d e n ; 
         s c r o l l b a r - w i d t h :   n o n e ; 
     } 
     . s e t t i n g s - t a b - b t n   { 
         p a d d i n g :   1 2 p x   1 5 p x ; 
         b o r d e r - l e f t :   n o n e ; 
         b o r d e r - b o t t o m :   3 p x   s o l i d   t r a n s p a r e n t ; 
         t e x t - a l i g n :   c e n t e r ; 
         w h i t e - s p a c e :   n o w r a p ; 
         w i d t h :   a u t o ; 
         f l e x :   1 ; 
     } 
     . s e t t i n g s - t a b - b t n . a c t i v e   { 
         b o r d e r - l e f t :   n o n e ; 
         b o r d e r - b o t t o m :   3 p x   s o l i d   v a r ( - - p r i m a r y ) ; 
     } 
     . s e t t i n g s - c o n t e n t   { 
         h e i g h t :   1 0 0 % ; 
         o v e r f l o w - y :   a u t o ; 
     } 
     # s e t t i n g s - m o d a l   . m o d a l - h e a d e r   { 
         p a d d i n g :   1 0 p x   1 5 p x ; 
     } 
     . s e t t i n g s - b o d y   { 
         p a d d i n g :   1 5 p x ; 
     } 
 } 
  
 