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

:root {
  --bg: linear-gradient(135deg, #0a0e27 0%, #1a1f3a 100%);
  --panel: rgba(20, 25, 45, 0.95);
  --panel-2: rgba(30, 35, 55, 0.9);
  --primary: #667eea;
  --accent: #764ba2;
  --text: #f0f4f8;
  --muted: #a0aec0;
  --success: #48bb78;
  --danger: #f56565;
  --border: rgba(102, 126, 234, 0.15);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  --glow: 0 0 20px rgba(102, 126, 234, 0.3);
}

/* Light Theme */
body:not(.dark-theme) {
  --bg: linear-gradient(135deg, #e0e7ff 0%, #f3f4f6 100%);
  --panel: rgba(255, 255, 255, 0.98);
  --panel-2: rgba(243, 244, 246, 0.95);
  --text: #1f2937;
  --muted: #6b7280;
  --border: rgba(102, 126, 234, 0.2);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  --glow: 0 0 20px rgba(102, 126, 234, 0.2);
}

body:not(.dark-theme) {
  background: linear-gradient(135deg, #e0e7ff 0%, #f3f4f6 100%);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: linear-gradient(135deg, #0a0e27 0%, #1a1f3a 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: 'Vazirmatn', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

#app {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0;
}

/* User List Container */
.user-list-container {
  width: 100%;
  max-width: 800px;
  height: 100vh;
  background: var(--panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  border-left: 2px solid var(--border);
  border-right: 2px solid var(--border);
}

.user-list-header {
  padding: 20px 24px;
  border-bottom: 2px solid var(--border);
  background: rgba(102, 126, 234, 0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.user-list-title {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.search-container {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.search-container .search {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  right: 16px;
  color: var(--muted);
  pointer-events: none;
  z-index: 1;
}

.search-container .search input {
  padding-right: 48px;
}

.user-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
}

/* Apply same scrollbar styling to user-list */
.user-list {
  scrollbar-width: thin;
  scrollbar-color: rgba(102, 126, 234, 0.6) transparent;
}

.user-list::-webkit-scrollbar {
  width: 10px;
}

.user-list::-webkit-scrollbar-track {
  background: transparent;
  margin: 4px 0;
}

.user-list::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, 
    rgba(102, 126, 234, 0.6) 0%, 
    rgba(118, 75, 162, 0.6) 50%,
    rgba(240, 147, 251, 0.6) 100%);
  border-radius: 10px;
  border: 2px solid transparent;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  transition: all 0.3s ease;
}

.user-list::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, 
    rgba(102, 126, 234, 0.9) 0%, 
    rgba(118, 75, 162, 0.9) 50%,
    rgba(240, 147, 251, 0.9) 100%);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.5);
  transform: scaleX(1.1);
}

.user-list::-webkit-scrollbar-thumb:active {
  background: linear-gradient(180deg, 
    rgba(102, 126, 234, 1) 0%, 
    rgba(118, 75, 162, 1) 50%,
    rgba(240, 147, 251, 1) 100%);
}

/* Responsive Design */
@media (max-width: 768px) {
  #app {
    padding: 0;
  }
  
  .user-list-container {
    max-width: 100%;
    border-left: none;
    border-right: none;
  }
  
  .user-list-header {
    padding: 16px 20px;
  }
  
  .user-list-title {
    font-size: 20px;
  }
  
  .search-container {
    padding: 12px 16px;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .user-list-container {
    max-width: 600px;
  }
}

/* Sidebar */
.sidebar {
  border-left: 2px solid var(--border);
  background: var(--panel);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
  max-height: 100%;
}
.sidebar-header {
  padding: 16px;
  border-bottom: 2px solid var(--border);
  background: rgba(102, 126, 234, 0.05);
  display: flex;
  align-items: center;
  gap: 12px;
}
.hamburger-btn {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.hamburger-btn:hover {
  background: rgba(102, 126, 234, 0.2);
  transform: scale(1.05);
}
.hamburger-btn:active {
  transform: scale(0.95);
}
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.brand {
  font-weight: 700;
}
.close-btn {
  display: none;
  background: transparent;
  color: var(--text);
  border: none;
  padding: 4px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
}
.close-btn:hover {
  background: rgba(255,255,255,0.1);
}
.close-btn svg {
  display: block;
}

@media (max-width: 768px) {
  .close-btn { display: block; }
}
.search { 
  margin-top: 0;
  position: relative;
  flex: 1;
}
.search input {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 2px solid var(--border);
  padding-left: 40px;
  border-radius: 12px;
  padding: 12px 16px;
  transition: all 0.3s ease;
  font-size: 14px;
}
.search input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--glow);
  transform: translateY(-2px);
}

/* Clear Search Button */
.clear-search-btn {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}
.clear-search-btn.visible {
  opacity: 1;
  visibility: visible;
}
.clear-search-btn:hover {
  background: rgba(245, 101, 101, 0.15);
  color: #f56565;
  transform: translateY(-50%) rotate(90deg);
}
.clear-search-btn:active {
  transform: translateY(-50%) scale(0.9);
}

.chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
}

/* Custom Scrollbar - شیک و مدرن برای همه مرورگرها */
.chat-list,
.messages {
  scrollbar-width: thin;
  scrollbar-color: rgba(102, 126, 234, 0.6) transparent;
}
.chat-list::-webkit-scrollbar,
.messages::-webkit-scrollbar {
  width: 10px;
}
.chat-list::-webkit-scrollbar-track,
.messages::-webkit-scrollbar-track {
  background: transparent;
  margin: 4px 0;
}
.chat-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, 
    rgba(102, 126, 234, 0.6) 0%, 
    rgba(118, 75, 162, 0.6) 50%,
    rgba(240, 147, 251, 0.6) 100%);
  border-radius: 10px;
  border: 2px solid var(--bg);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  transition: all 0.3s ease;
}
.chat-list::-webkit-scrollbar-thumb:hover,
.messages::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, 
    rgba(102, 126, 234, 0.9) 0%, 
    rgba(118, 75, 162, 0.9) 50%,
    rgba(240, 147, 251, 0.9) 100%);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.5);
  transform: scaleX(1.1);
}
.chat-list::-webkit-scrollbar-thumb:active,
.messages::-webkit-scrollbar-thumb:active {
  background: linear-gradient(180deg, 
    rgba(102, 126, 234, 1) 0%, 
    rgba(118, 75, 162, 1) 50%,
    rgba(240, 147, 251, 1) 100%);
}
.chat-item {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
}
.chat-item::before {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  opacity: 0;
  transition: opacity 0.3s ease;
}
.chat-item:hover {
  background: rgba(102, 126, 234, 0.1);
  transform: translateX(-4px);
}
.chat-item:hover::before {
  opacity: 1;
}
.avatar {
  width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
  font-size: 18px;
  transition: transform 0.3s ease;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.avatar-text {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  border-radius: 50%;
}
.chat-item:hover .avatar {
  transform: scale(1.1) rotate(5deg);
}
.chat-meta { min-width: 0; }
.chat-name {
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}
.gender-icon {
  flex-shrink: 0;
  vertical-align: middle;
  display: inline-block;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}
.chat-preview {
  font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badges { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.time { font-size: 11px; color: var(--muted); }
.unread {
  min-width: 24px; height: 24px; padding: 0 8px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #f093fb, #f5576c);
  color: #fff; border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(245, 87, 108, 0.4);
  animation: pulse-badge 2s ease-in-out infinite;
}
.search-count {
  min-width: 24px; height: 24px; padding: 0 8px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff; border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
  animation: search-glow 2s ease-in-out infinite;
}

/* No results state */
.no-results {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  gap: 16px;
  height: 100%;
  min-height: 100%;
}
.no-results-icon {
  width: 64px;
  height: 64px;
  opacity: 0.5;
  color: var(--muted);
  animation: float-icon 3s ease-in-out infinite;
}
.no-results-text {
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--muted);
}
@keyframes float-icon {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
}
@keyframes pulse-badge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}
@keyframes search-glow {
  0%, 100% { box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4); }
  50% { box-shadow: 0 4px 20px rgba(102, 126, 234, 0.7); }
}

/* Chat */
.chat { 
  display: grid; 
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  max-height: 100%;
  position: relative;
  /* isolation: isolate; */
}

/* Top Header */
.top-header {
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.15) 0%, rgba(118, 75, 162, 0.15) 100%);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-bottom: 2px solid var(--border);
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  box-shadow: var(--shadow);
}
.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  order: 2;
}
.current-user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.5);
  transition: transform 0.3s ease;
  cursor: pointer;
}
.current-user-avatar:hover {
  transform: scale(1.1) rotate(5deg);
}
.current-user-name {
  font-size: 20px;
  font-weight: 800;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 1px;
  filter: drop-shadow(0 0 10px rgba(102, 126, 234, 0.5));
  animation: gradient-shift 3s ease infinite;
  background-size: 200% 200%;
}
@keyframes gradient-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.logo-container {
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
.logo-icon {
  height: 45px;
  width: auto;
  filter: drop-shadow(0 0 15px rgba(102, 126, 234, 0.6));
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
}

.chat-header {
  border-bottom: 2px solid var(--border);
  background: rgba(102, 126, 234, 0.05);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 5001;
  overflow: visible;
}
.chat-header::after {
  content: '';
  flex: 1;
  order: 50;
}
.peer-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
  transition: transform 0.3s ease;
  flex-shrink: 0;
  overflow: hidden;
  cursor: pointer;
}
.peer-avatar:empty {
  background: rgba(102, 126, 234, 0.2);
  border: 2px dashed var(--border);
}
.peer-avatar .avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.peer-meta { min-width: 0; }
.peer-name { font-weight: 700; }
.peer-status { color: var(--muted); font-size: 12px; }

/* Chat Search Bar */
.chat-search-container {
  position: relative;
  order: 60;
  z-index: 5000;
}
.chat-search-toggle {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}
.chat-search-toggle:hover {
  background: rgba(102, 126, 234, 0.2);
  transform: scale(1.1);
}
.chat-search-toggle.active {
  background: rgba(102, 126, 234, 0.3);
  color: #fbbf24;
}
.chat-search-box {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: auto;
  width: 280px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  z-index: 5000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.chat-search-box.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  z-index: 5000;
}
.chat-search-box input {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 15px;
  transition: all 0.3s ease;
}
.chat-search-box input:focus {
  outline: none;
  border-color: #fbbf24;
  box-shadow: 0 0 15px rgba(251, 191, 36, 0.4);
}

@media (max-width: 768px) {
  .chat-search-box {
    width: 280px;
    padding: 0;
  }
  .chat-search-box input {
    font-size: 16px;
    padding: 14px 18px;
  }
}

/* Search Navigation */
.search-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.15), rgba(118, 75, 162, 0.15));
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  padding: 10px 14px;
  border-radius: 14px;
  border: 2px solid var(--border);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.9);
  transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
  position: absolute;
  bottom: 80px;
  left: 20px;
  z-index: 10;
}
.search-nav.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}
.search-counter {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  min-width: 55px;
  text-align: center;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.search-nav-btn,
.search-close-btn {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  min-width: 36px;
  min-height: 36px;
}
.search-nav-btn:hover {
  background: rgba(102, 126, 234, 0.2);
  transform: translateY(-2px);
}
.search-nav-btn:active {
  transform: translateY(0) scale(0.95);
}
.search-close-btn {
  color: #f56565;
}
.search-close-btn:hover {
  background: rgba(245, 101, 101, 0.15);
  transform: rotate(90deg);
}
.search-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.search-nav-btn:disabled:hover {
  background: transparent;
  transform: none;
}

@media (max-width: 768px) {
  .search-nav {
    padding: 12px 16px;
    gap: 12px;
    bottom: 90px;
  }
  .search-counter {
    font-size: 15px;
    min-width: 60px;
  }
  .search-nav-btn,
  .search-close-btn {
    padding: 10px;
    min-width: 44px;
    min-height: 44px;
  }
  .search-nav-btn svg,
  .search-close-btn svg {
    width: 22px;
    height: 22px;
  }
}

.messages {
  background: 
    radial-gradient(circle at 20% 50%, rgba(102, 126, 234, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(118, 75, 162, 0.03) 0%, transparent 50%),
    url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 10 10"><circle cx="1" cy="1" r="0.8" fill="%23667eea" opacity="0.1"/></svg>') repeat;
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  max-height: 100%;
}
.empty-state {
  margin: auto;
  text-align: center;
  color: var(--muted);
}

/* Chat State (Loading & Empty) */
.chat-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px 20px;
  text-align: center;
  color: #8e8e93;
}

.chat-state-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.chat-state-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #e4e6eb;
}

.chat-state-message {
  font-size: 14px;
  line-height: 1.5;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(107, 138, 253, 0.2);
  border-top-color: #6b8afd;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
.message-row { 
  margin: 8px 0; 
  display: flex; 
  position: relative;
  touch-action: pan-y;
  transition: transform 0.3s ease;
  cursor: grab;
  user-select: none;
  width: fit-content;
  max-width: 50%;
}
.message-row:active {
  cursor: grabbing;
}
.message-row::before {
  content: '';
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: -1;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='9 14 4 9 9 4'%3E%3C/polyline%3E%3Cpath d='M20 20v-7a4 4 0 0 0-4-4H4'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 18px;
}
.sent.message-row::before {
  right: -40px;
}
.received.message-row::before {
  left: -40px;
  transform: translateY(-50%) scaleX(-1);
}
.message-row.swipe-hint::before {
  opacity: 1;
}
.message {
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  white-space: normal;
  word-wrap: break-word;
  line-height: 1.3;
  font-size: 15px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}
.message:hover {
  transform: translateY(-2px);
}

@media (max-width: 768px) {
  .message-row {
    margin-bottom: 12px;
    max-width: 75%;
  }
  .message {
    font-size: 14px;
    padding: 8px 12px;
  }
}
.sent { 
  justify-content: flex-end;
  margin-left: auto;
}
.sent .message { 
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.2), rgba(102, 126, 234, 0.3));
  border-color: rgba(102, 126, 234, 0.4);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}
.received { 
  justify-content: flex-start;
  margin-right: auto;
}
.received .message { 
  background: linear-gradient(135deg, rgba(118, 75, 162, 0.2), rgba(240, 147, 251, 0.2));
  border-color: rgba(118, 75, 162, 0.4);
  box-shadow: 0 4px 12px rgba(118, 75, 162, 0.2);
}
.meta { 
  margin-top: 4px; 
  font-size: 11px; 
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.star-icon {
  flex-shrink: 0;
  animation: starPulse 2s ease-in-out infinite;
}
@keyframes starPulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }
}

/* Message sender label (for saved messages) */
.message-sender-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(102, 126, 234, 0.2);
}

/* Reply preview in message */
.reply-preview {
  background: rgba(102, 126, 234, 0.1);
  border-left: 3px solid var(--primary);
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.reply-preview:hover {
  background: rgba(102, 126, 234, 0.2);
  transform: translateX(-2px);
}
.reply-sender {
  font-weight: 700;
  color: var(--primary);
  font-size: 12px;
  margin-bottom: 4px;
}
.reply-text {
  font-size: 12px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  max-height: 2.8em; /* 2 lines * 1.4 line-height */
  word-wrap: break-word;
  word-break: break-word;
}

/* Message highlight animation */
.message-highlight {
  animation: messageHighlight 1s ease-in-out;
  border-radius: 14px;
}

@keyframes messageHighlight {
  0% {
    box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.8);
  }
  15% {
    box-shadow: 0 0 0 6px rgba(251, 191, 36, 0.5),
                0 0 0 12px rgba(251, 191, 36, 0.25);
  }
  30% {
    box-shadow: 0 0 0 6px rgba(251, 191, 36, 0.5),
                0 0 0 12px rgba(251, 191, 36, 0.25);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(251, 191, 36, 0);
  }
}

.message-highlight .message {
  animation: messageBorderPulse 1s ease-in-out;
}

@keyframes messageBorderPulse {
  0% {
    border-color: var(--border);
    border-width: 1px;
  }
  15% {
    border-color: #fbbf24;
    border-width: 3px;
  }
  30% {
    border-color: #fbbf24;
    border-width: 3px;
  }
  100% {
    border-color: var(--border);
    border-width: 1px;
  }
}

/* Message context active state (yellow border) */
.message.context-active {
  border-color: #fbbf24;
  border-width: 1px;
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.2),
              0 2px 6px rgba(251, 191, 36, 0.3);
  transition: all 0.2s ease;
  position: relative;
  z-index: 4000;
}
.message-row:has(.message.context-active) {
  position: relative;
  z-index: 4000;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.95), rgba(118, 75, 162, 0.95));
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  color: white;
  padding: 12px 24px;
  border-radius: 50px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  z-index: 4000;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}
.toast.active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast svg {
  flex-shrink: 0;
}

/* Context Menu Backdrop */
.context-menu-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  /* Add vendor prefixes for Safari support */
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  z-index: 2999;
  opacity: 0;
  pointer-events: none;
  /* Add webkit prefix for transitions */
  -webkit-transition: opacity 0.3s ease, backdrop-filter 0.3s ease, -webkit-backdrop-filter 0.3s ease;
  transition: opacity 0.3s ease, backdrop-filter 0.3s ease, -webkit-backdrop-filter 0.3s ease;
  /* Force hardware acceleration for better performance */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  will-change: opacity;
}
.context-menu-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* Message Context Menu */
.message-context-menu {
  position: fixed;
  /* background: var(--panel); */
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border: 2px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  padding: 8px;
  display: none;
  flex-direction: column;
  gap: 4px;
  z-index: 3000;
  min-width: 180px;
  animation: contextMenuAppear 0.2s ease;
}
.message-context-menu.active {
  display: flex;
}
.context-menu-item {
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(102, 126, 234, 0.15);
  color: var(--text);
  cursor: pointer;
  padding: 12px 16px;
  border-radius: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  text-align: right;
}
.context-menu-item:first-child {
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}
.context-menu-item:last-child {
  border-bottom: none;
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
}
.context-menu-item:hover {
  background: rgba(102, 126, 234, 0.2);
  transform: translateX(-2px);
}
.context-menu-item svg {
  flex-shrink: 0;
}
.context-menu-item.delete-item {
  color: #f56565;
}
.context-menu-item.delete-item:hover {
  background: rgba(245, 101, 101, 0.2);
}

@keyframes contextMenuAppear {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Reply bar */
.reply-bar {
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
  border-top: 2px solid var(--border);
  border-bottom: 2px solid var(--border);
  padding: 12px 16px;
  display: none;
  align-items: center;
  gap: 12px;
  animation: slideDown 0.3s ease;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.reply-bar.active {
  display: flex;
}
.reply-bar-content {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}
.reply-bar-icon {
  color: var(--primary);
  display: flex;
  align-items: center;
}
.reply-bar-info {
  flex: 1;
  min-width: 0;
}
.reply-bar-sender {
  font-weight: 700;
  color: var(--primary);
  font-size: 13px;
  margin-bottom: 2px;
}
.reply-bar-text {
  font-size: 12px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  max-height: 2.8em; /* 2 lines * 1.4 line-height */
  word-wrap: break-word;
  word-break: break-word;
}
@media (max-width: 480px) {
  .reply-bar {
    padding: 8px 12px;
    gap: 8px;
  }
  .reply-bar-content {
    gap: 8px;
  }
  .reply-bar-icon {
    flex-shrink: 0;
  }
  .reply-bar-sender {
    font-size: 12px;
  }
  .reply-bar-text {
    font-size: 11px;
    -webkit-line-clamp: 1;
    max-height: 1.4em; /* 1 line in mobile */
  }
}

.cancel-reply-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.cancel-reply-btn:hover {
  background: rgba(245, 101, 101, 0.2);
  color: #f56565;
  transform: rotate(90deg);
}

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

/* Search highlight */
.highlight {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #1a1f3a;
  padding: 2px 4px;
  border-radius: 4px;
  font-weight: 700;
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
  animation: highlight-pulse 1.5s ease-in-out infinite;
}

/* Highlight in chat list (sidebar) */
.chat-name .highlight,
.chat-preview .highlight {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #0a0e27;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(251, 191, 36, 0.6);
  display: inline-block;
  animation: sidebar-highlight-glow 1.5s ease-in-out infinite;
}

/* Highlight in messages */
.message .text .highlight {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #1a1f3a;
  padding: 2px 4px;
  border-radius: 4px;
  font-weight: 700;
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
}

@keyframes highlight-pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(251, 191, 36, 0.5); }
  50% { box-shadow: 0 0 20px rgba(251, 191, 36, 0.8); }
}

@keyframes sidebar-highlight-glow {
  0%, 100% { 
    box-shadow: 0 2px 8px rgba(251, 191, 36, 0.6);
    transform: scale(1);
  }
  50% { 
    box-shadow: 0 4px 16px rgba(251, 191, 36, 0.9);
    transform: scale(1.05);
  }
}

.has-search-match .message {
  border: 2px solid rgba(251, 191, 36, 0.2) !important;
  box-shadow: 0 2px 8px rgba(251, 191, 36, 0.15) !important;
}

/* Active match - only the current focused message */
.active-match .message {
  border: 3px solid rgba(251, 191, 36, 0.9) !important;
  box-shadow: 0 6px 30px rgba(251, 191, 36, 0.6) !important;
  animation: active-match-glow 1.5s ease-in-out infinite;
  transform: scale(1.03);
}

@keyframes active-match-glow {
  0%, 100% { 
    box-shadow: 0 6px 30px rgba(251, 191, 36, 0.6);
    border-color: rgba(251, 191, 36, 0.9);
  }
  50% { 
    box-shadow: 0 8px 40px rgba(251, 191, 36, 0.9);
    border-color: rgba(251, 191, 36, 1);
  }
}

.composer {
  border-top: 2px solid var(--border);
  background: rgba(102, 126, 234, 0.05);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  padding: 12px 16px;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
  align-items: center;
  position: relative;
}
.composer-menu-wrapper {
  position: relative;
}
.attach-menu-btn {
  background: transparent;
  color: var(--primary);
  border: none;
  padding: 8px;
  cursor: pointer;
  border-radius: 10px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attach-menu-btn:hover {
  background: rgba(102, 126, 234, 0.15);
  transform: rotate(90deg);
}
.attach-menu {
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 8px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.3s ease;
  box-shadow: var(--shadow);
  z-index: 1000;
}
.attach-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.attach-btn,
.photo-btn,
.voice-btn {
  background: transparent;
  color: var(--text);
  border: none;
  padding: 10px 14px;
  cursor: pointer;
  border-radius: 10px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  font-size: 14px;
}
.attach-btn:hover,
.photo-btn:hover,
.voice-btn:hover {
  background: rgba(102, 126, 234, 0.2);
  transform: translateX(-4px);
}
.attach-btn svg,
.photo-btn svg,
.voice-btn svg {
  display: block;
  flex-shrink: 0;
}
.composer textarea {
  background: var(--panel-2);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 10px 10px 10px 18px;
  font-size: 15px;
  transition: all 0.3s ease;
  resize: none;
  overflow-y: auto;
  height: 60px;
  font-family: inherit;
  line-height: 1.5;
  direction: ltr;
  text-align: right;
  unicode-bidi: plaintext;
}
.composer textarea {
  scrollbar-width: thin;
  scrollbar-color: rgba(102, 126, 234, 0.5) transparent;
  scrollbar-gutter: stable;
}
.composer textarea::-webkit-scrollbar {
  width: 3px;
}
.composer textarea::-webkit-scrollbar-track {
  background: transparent;
  margin: 8px 0;
}
.composer textarea::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, 
    rgba(102, 126, 234, 0.5) 0%, 
    rgba(118, 75, 162, 0.5) 50%,
    rgba(240, 147, 251, 0.5) 100%);
  border-radius: 6px;
  border: 1px solid rgba(102, 126, 234, 0.2);
  box-shadow: 0 2px 6px rgba(102, 126, 234, 0.2);
  transition: all 0.3s ease;
}
.composer textarea::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, 
    rgba(102, 126, 234, 0.8) 0%, 
    rgba(118, 75, 162, 0.8) 50%,
    rgba(240, 147, 251, 0.8) 100%);
  box-shadow: 0 3px 10px rgba(102, 126, 234, 0.4);
  transform: scaleX(1.3);
}
.composer textarea::-webkit-scrollbar-thumb:active {
  background: linear-gradient(180deg, 
    rgba(102, 126, 234, 1) 0%, 
    rgba(118, 75, 162, 1) 50%,
    rgba(240, 147, 251, 1) 100%);
}
.composer textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--glow);
  transform: translateY(-2px);
}
#sendBtn {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
#sendBtn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}
#sendBtn:active {
  transform: scale(0.95);
}
#sendBtn svg {
  display: block;
}

/* Mobile menu button */
.menu-btn,
.back-btn {
  display: none;
  background: transparent;
  color: var(--text);
  border: none;
  padding: 8px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
  flex-shrink: 0;
}
.menu-btn:hover,
.back-btn:hover {
  background: rgba(255,255,255,0.05);
}
.menu-btn svg,
.back-btn svg {
  display: block;
}
.back-btn {
  order: 70;
}

@media (max-width: 768px) {
  .menu-btn { display: none; }
  .back-btn { display: block; }
}

/* Left Navigation Panel */
.left-nav {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100vh;
  background: var(--panel);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-right: 2px solid var(--border);
  box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  z-index: 1000;
  display: flex;
  flex-direction: column;
}
.left-nav.active {
  transform: translateX(0);
}
.left-nav-header {
  padding: 20px;
  border-bottom: 2px solid var(--border);
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
  display: flex;
  align-items: center;
  justify-content: flex-start;
}
.left-nav-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.close-nav-btn {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.close-nav-btn:hover {
  background: rgba(245, 101, 101, 0.15);
  color: #f56565;
  transform: rotate(90deg);
}
.left-nav-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
}
.left-nav-content {
  scrollbar-width: thin;
  scrollbar-color: rgba(102, 126, 234, 0.5) transparent;
}
.left-nav-content::-webkit-scrollbar {
  width: 8px;
}
.left-nav-content::-webkit-scrollbar-track {
  background: transparent;
  margin: 4px 0;
}
.left-nav-content::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, 
    rgba(102, 126, 234, 0.5) 0%, 
    rgba(118, 75, 162, 0.5) 50%,
    rgba(240, 147, 251, 0.5) 100%);
  border-radius: 8px;
  border: 1px solid rgba(102, 126, 234, 0.2);
  box-shadow: 0 2px 6px rgba(102, 126, 234, 0.2);
  transition: all 0.3s ease;
}
.left-nav-content::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, 
    rgba(102, 126, 234, 0.8) 0%, 
    rgba(118, 75, 162, 0.8) 50%,
    rgba(240, 147, 251, 0.8) 100%);
  box-shadow: 0 3px 10px rgba(102, 126, 234, 0.4);
  transform: scaleX(1.2);
}
.left-nav-content::-webkit-scrollbar-thumb:active {
  background: linear-gradient(180deg, 
    rgba(102, 126, 234, 1) 0%, 
    rgba(118, 75, 162, 1) 50%,
    rgba(240, 147, 251, 1) 100%);
}
.nav-menu {
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  cursor: pointer;
  transition: all 0.3s ease;
  border-left: 3px solid transparent;
  position: relative;
}
.nav-item:hover {
  background: rgba(102, 126, 234, 0.1);
  border-left-color: var(--primary);
  transform: translateX(4px);
}
.nav-item svg {
  color: var(--primary);
  flex-shrink: 0;
}
.nav-item span {
  font-size: 15px;
  font-weight: 500;
  flex: 1;
}
.nav-item-expandable {
  justify-content: space-between;
}
.expand-icon {
  color: var(--muted);
  transition: transform 0.3s ease;
  margin-left: auto;
}
.nav-item-expandable.expanded .expand-icon {
  transform: rotate(180deg);
}

/* Submenu */
.nav-submenu {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  background: rgba(102, 126, 234, 0.05);
}
.nav-submenu.expanded {
  max-height: 300px;
}
.nav-subitem {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px 12px 56px;
  cursor: pointer;
  transition: all 0.3s ease;
  border-left: 3px solid transparent;
}
.nav-subitem:hover {
  background: rgba(102, 126, 234, 0.15);
  border-left-color: var(--accent);
  transform: translateX(4px);
}
.nav-subitem svg {
  color: var(--accent);
  flex-shrink: 0;
}
.nav-subitem span {
  font-size: 14px;
  font-weight: 400;
  flex: 1;
}

/* Theme Toggle Switch */
.theme-toggle-item {
  justify-content: space-between;
}
.theme-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 24px;
  flex-shrink: 0;
}
.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.theme-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #667eea, #764ba2);
  transition: 0.4s;
  border-radius: 24px;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}
.theme-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
input:checked + .theme-slider {
  background: linear-gradient(135deg, #1a1f3a, #0a0e27);
}
input:checked + .theme-slider:before {
  transform: translateX(24px);
}
.theme-slider:hover {
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.5);
}

/* Premium Item */
.premium-item .premium-icon {
  color: #fbbf24 !important;
  filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.6));
}
.premium-item:hover .premium-icon {
  filter: drop-shadow(0 0 12px rgba(251, 191, 36, 0.8));
}

/* Overlay */
.nav-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 999;
}
.nav-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Profile Popup */
.profile-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 1001;
}
.profile-popup.active {
  opacity: 1;
  visibility: visible;
}
.profile-popup-content {
  background: var(--panel);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border: 2px solid var(--border);
  border-radius: 24px;
  padding: 28px;
  max-width: 360px;
  width: 70%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  position: relative;
  transform: scale(0.9) translateY(20px);
  transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.profile-popup.active .profile-popup-content {
  transform: scale(1) translateY(0);
}
.close-profile-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.close-profile-btn:hover {
  background: rgba(245, 101, 101, 0.15);
  color: #f56565;
  transform: rotate(90deg);
}
.profile-header {
  text-align: center;
  margin-bottom: 24px;
}
.profile-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
  font-weight: 700;
  margin: 0 auto 16px;
  box-shadow: 0 8px 24px rgba(102, 126, 234, 0.4);
  animation: profile-pulse 2s ease-in-out infinite;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.3s ease;
}
.profile-avatar:hover {
  transform: scale(1.05);
}
.profile-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
@keyframes profile-pulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(102, 126, 234, 0.4); }
  50% { box-shadow: 0 8px 32px rgba(102, 126, 234, 0.6); }
}
.profile-name {
  margin: 0 0 8px 0;
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.profile-username {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}
.profile-bio {
  background: rgba(102, 126, 234, 0.05);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 20px;
}
.bio-title {
  margin: 0 0 12px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
}
.bio-text {
  margin: 0;
  color: var(--text);
  line-height: 1.6;
  font-size: 14px;
}
.profile-coins {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.1), rgba(245, 158, 11, 0.1));
  border: 2px solid rgba(251, 191, 36, 0.3);
  border-radius: 16px;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.coin-icon {
  color: #fbbf24;
  filter: drop-shadow(0 0 8px rgba(251, 191, 36, 0.6));
  flex-shrink: 0;
}
.coin-count {
  font-size: 24px;
  font-weight: 700;
  color: #fbbf24;
  text-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
}
.coin-label {
  font-size: 16px;
  color: var(--text);
  font-weight: 500;
}

/* Avatar Modal */
.avatar-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 2000;
}
.avatar-modal.active {
  opacity: 1;
  visibility: visible;
}
.avatar-modal-content {
  max-width: 63%;
  max-height: 63%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  transform: scale(0.8);
  transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.avatar-modal.active .avatar-modal-content {
  transform: scale(1);
}
.avatar-modal-content img {
  max-width: 100%;
  max-height: 49vh;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  border: 3px solid var(--border);
}
.avatar-modal-name {
  color: var(--text);
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 20px rgba(102, 126, 234, 0.5);
}
.close-avatar-btn {
  position: absolute;
  top: 20px;
  left: 20px;
  background: rgba(255, 255, 255, 0.1);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2001;
  width: 38px;
  height: 38px;
}
.close-avatar-btn svg {
  width: 22px;
  height: 22px;
}
.close-avatar-btn:hover {
  background: rgba(245, 101, 101, 0.3);
  border-color: #f56565;
  color: #f56565;
  transform: rotate(90deg) scale(1.1);
}

/* Web App Modal */
.webapp-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for mobile */
  background: var(--panel);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translateY(100%);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 3000;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

.webapp-modal.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.webapp-modal-header {
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1));
  border-bottom: 2px solid var(--border);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.webapp-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.close-webapp-btn {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.close-webapp-btn:hover {
  background: rgba(245, 101, 101, 0.2);
  border-color: #f56565;
  color: #f56565;
  transform: rotate(90deg);
}

.webapp-frame {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  -ms-touch-action: pan-x pan-y;
}
