/* ============================================
   ChatApp — Premium CSS Stylesheet
   Modern Dark Theme with Glassmorphism
   ============================================ */

/* === CSS Variables (Premium Dark Theme) === */
:root {
  --bg-primary: #0f172a;       /* Slate 900 */
  --bg-secondary: #1e293b;     /* Slate 800 */
  --bg-tertiary: #334155;      /* Slate 700 */
  --bg-hover: #1e293b;
  --sent-bubble: #3b82f6;      /* Blue 500 */
  --received-bubble: #1e293b;  /* Slate 800 */
  --accent: #3b82f6;           /* Blue 500 */
  --accent-hover: #2563eb;     /* Blue 600 */
  --accent-glow: rgba(59, 130, 246, 0.4);
  --accent-soft: rgba(59, 130, 246, 0.15);
  --online: #10b981;           /* Emerald 500 */
  --online-glow: rgba(16, 185, 129, 0.4);
  --text-primary: #f8fafc;     /* Slate 50 */
  --text-secondary: #cbd5e1;   /* Slate 300 */
  --text-muted: #94a3b8;       /* Slate 400 */
  --border: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.04);
  --danger: #ef4444;
  --success: #10b981;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 12px rgba(59, 130, 246, 0.3);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-2xl: 24px;
  --radius-pill: 9999px;
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s ease;
  --transition-slow: 0.3s ease;
  --transition-spring: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html {
  height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  line-height: 1.5;
  font-size: 14px;
}

::selection {
  background: var(--accent);
  color: white;
}

::-moz-selection {
  background: var(--accent);
  color: white;
}

input, button, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  outline: none;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  text-decoration: none;
  color: var(--accent);
}

/* === Custom Scrollbar === */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(129, 140, 248, 0.3);
  border-radius: var(--radius-pill);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(129, 140, 248, 0.5);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(129, 140, 248, 0.3) transparent;
}

/* === Utility Classes === */
.hidden {
  display: none !important;
}

.screen {
  display: none;
  width: 100%;
  height: 100vh;
}

.screen.active {
  display: flex;
}

/* ============================================
   AUTH SCREEN
   ============================================ */
#auth-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
              radial-gradient(ellipse at 80% 80%, rgba(139, 92, 246, 0.1) 0%, transparent 40%),
              radial-gradient(ellipse at 20% 90%, rgba(59, 130, 246, 0.08) 0%, transparent 40%),
              var(--bg-primary);
  position: relative;
  overflow: hidden;
}

/* Animated gradient orbs */
#auth-screen::before {
  content: '';
  position: absolute;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.12) 0%, transparent 70%);
  top: -200px;
  right: -100px;
  border-radius: 50%;
  filter: blur(60px);
  animation: floatOrb1 8s ease-in-out infinite;
  pointer-events: none;
}

#auth-screen::after {
  content: '';
  position: absolute;
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.1) 0%, transparent 70%);
  bottom: -150px;
  left: -100px;
  border-radius: 50%;
  filter: blur(60px);
  animation: floatOrb2 10s ease-in-out infinite;
  pointer-events: none;
}

@keyframes floatOrb1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, 20px) scale(1.1); }
  66% { transform: translate(-20px, -10px) scale(0.95); }
}

@keyframes floatOrb2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(-25px, -15px) scale(1.05); }
  66% { transform: translate(15px, 25px) scale(1.1); }
}

/* Auth Container — Glassmorphism */
.auth-container {
  max-width: 420px;
  width: 90%;
  background: rgba(18, 18, 26, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-2xl);
  padding: 40px;
  position: relative;
  z-index: 1;
  animation: slideUp 0.6s ease-out;
  box-shadow: var(--shadow-lg),
              0 0 80px rgba(99, 102, 241, 0.05);
}

.auth-header {
  text-align: center;
  margin-bottom: 32px;
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  font-size: 48px;
  animation: bounceIn 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(0 4px 12px rgba(99, 102, 241, 0.3));
}

.logo h1 {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, #818cf8, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.logo p {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 400;
}

/* Auth Tabs */
.auth-tabs {
  display: flex;
  background: var(--bg-tertiary);
  border-radius: var(--radius-pill);
  padding: 4px;
  margin-bottom: 28px;
  position: relative;
}

.auth-tab {
  flex: 1;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition-base);
  position: relative;
  z-index: 1;
}

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

.auth-tab.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 8px rgba(129, 140, 248, 0.4);
}

/* Auth Forms */
.auth-form {
  display: none;
  flex-direction: column;
  gap: 18px;
  animation: fadeIn 0.3s ease;
}

.auth-form.active {
  display: flex;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  padding-left: 4px;
}

.form-group input {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 14px;
  transition: all var(--transition-base);
}

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

.form-group input:hover {
  border-color: rgba(255, 255, 255, 0.1);
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: rgba(26, 26, 46, 0.8);
}

/* Primary Button */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  color: white;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-slow);
  position: relative;
  overflow: hidden;
  margin-top: 4px;
}

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

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

.btn-primary:hover {
  box-shadow: var(--shadow-glow), 0 4px 16px rgba(129, 140, 248, 0.4);
  transform: translateY(-1px) scale(1.02);
}

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-primary:disabled:hover {
  box-shadow: none;
  transform: none;
}

.btn-primary:disabled::before {
  display: none;
}

/* Button Loader */
.btn-loader {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* Error Message */
.error-message {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  padding: 8px 12px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-sm);
  animation: slideDown 0.3s ease;
}

/* ============================================
   CHAT SCREEN
   ============================================ */
#chat-screen {
  flex-direction: row;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-primary);
}

/* === Sidebar === */
.sidebar {
  width: 380px;
  min-width: 380px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  z-index: 10;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  min-height: 72px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, #667eea, #764ba2);
  flex-shrink: 0;
  user-select: none;
}

.user-details h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.user-details p {
  font-size: 12px;
  color: var(--online);
  font-weight: 500;
}

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

/* Icon Button */
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition-base);
  position: relative;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.icon-btn:active {
  transform: scale(0.92);
}

/* Search Bar */
.search-container {
  padding: 12px 16px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 28px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 10px 16px 10px 40px;
  color: var(--text-primary);
  font-size: 13px;
  transition: all var(--transition-base);
}

#search-input::placeholder {
  color: var(--text-muted);
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: rgba(26, 26, 46, 0.8);
}

/* Conversations List */
.conversations-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.conversation-item {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  gap: 12px;
  cursor: pointer;
  transition: all var(--transition-base);
  position: relative;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  animation: fadeIn 0.3s ease;
}

.conversation-item:hover {
  background: var(--bg-hover);
}

.conversation-item.active {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
}

.conversation-item.active .conversation-name {
  color: var(--accent);
}

.conversation-avatar {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: white;
  position: relative;
  flex-shrink: 0;
  user-select: none;
}

.conversation-avatar .online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 12px;
  height: 12px;
  background: var(--online);
  border: 2.5px solid var(--bg-secondary);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--online-glow);
}

.conversation-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.conversation-last-message {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.conversation-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.conversation-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  font-weight: 500;
}

.unread-badge {
  min-width: 20px;
  height: 20px;
  background: var(--accent);
  color: white;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  animation: pulseIn 0.3s ease;
  box-shadow: 0 0 8px var(--accent-glow);
}

.conversations-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
  gap: 12px;
}

.conversations-empty .empty-conversations-icon {
  font-size: 40px;
  opacity: 0.5;
}

.conversations-empty p {
  font-size: 14px;
}

/* === Chat Area === */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  background: var(--bg-primary);
  position: relative;
}

/* Empty State */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 40px;
  animation: fadeIn 0.5s ease;
}

.empty-icon {
  font-size: 64px;
  animation: bounceIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(0 4px 16px rgba(99, 102, 241, 0.2));
  margin-bottom: 8px;
}

.empty-state h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.empty-state p {
  font-size: 15px;
  color: var(--text-muted);
  max-width: 300px;
}

/* Chat View */
.chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

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

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  min-height: 68px;
  background: var(--bg-primary);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  gap: 8px;
  z-index: 5;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
  user-select: none;
}

.chat-header-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header-details h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-details p {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 400;
}

.chat-header-details p.online-status {
  color: var(--online);
  font-weight: 500;
}

/* Messages Container */
.messages-container {
  flex: 1;
  padding: 20px 5%;
  overflow-y: auto;
  background-color: var(--bg-primary);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Date Separator */
.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 0 12px;
  position: relative;
}

.date-separator span {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 14px;
  border-radius: var(--radius-pill);
  position: relative;
  z-index: 1;
  border: 1px solid var(--border);
}

/* Message */
.message {
  display: flex;
  flex-direction: column;
  max-width: 65%;
  position: relative;
}

.message.sent {
  align-self: flex-end;
  align-items: flex-end;
  animation: slideInRight 0.3s ease;
}

.message.received {
  align-self: flex-start;
  align-items: flex-start;
  animation: slideInLeft 0.3s ease;
}

.message-sender-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  padding: 0 8px;
  margin-bottom: 2px;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 18px 18px 18px 18px;
  word-wrap: break-word;
  word-break: break-word;
  position: relative;
  line-height: 1.5;
  font-size: 14px;
}

.message-bubble img.chat-image {
  max-width: 100%;
  max-height: 250px;
  border-radius: 8px;
  margin-top: 4px;
  cursor: pointer;
}

.message-bubble video.chat-video {
  max-width: 100%;
  max-height: 250px;
  border-radius: 8px;
  margin-top: 4px;
  outline: none;
}

.message-bubble a.chat-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 6px;
  color: inherit;
  text-decoration: none;
  font-weight: 500;
  margin-top: 4px;
}

.message-bubble a.chat-file:hover {
  background: rgba(0, 0, 0, 0.15);
}

.message.sent .message-bubble {
  background: var(--sent-bubble);
  color: var(--text-primary);
  border-radius: 8px 0 8px 8px;
  box-shadow: var(--shadow-sm);
}

.message.received .message-bubble {
  background: var(--received-bubble);
  color: var(--text-primary);
  border-radius: 0 8px 8px 8px;
  box-shadow: var(--shadow-sm);
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.message.sent .message-time {
  color: var(--text-muted);
}

/* Message status check marks */
.message-status {
  display: inline-flex;
  font-size: 13px;
}

.message-status.read {
  color: #60a5fa;
}

/* Consecutive messages spacing */
.message + .message {
  margin-top: 2px;
}

.message.sent + .message.received,
.message.received + .message.sent {
  margin-top: 12px;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-self: flex-start;
  animation: slideInLeft 0.3s ease;
  margin-top: 2px;
}

.typing-indicator.hidden {
  display: none !important;
}

.typing-bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
}

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

.typing-dots {
  display: flex;
  gap: 3px;
  align-items: center;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) {
  animation-delay: 0s;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

/* Message Input */
.message-input-container {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
  position: relative;
}

/* ==========================================
   ATTACHMENT MENU (WhatsApp-style)
   ========================================== */
.attachment-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 12px;
  background: var(--bg-secondary);
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 260px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  z-index: 100;
  transform-origin: bottom left;
  animation: attachMenuOpen 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.attachment-menu.hidden {
  display: none;
}

@keyframes attachMenuOpen {
  from {
    opacity: 0;
    transform: scale(0.85) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.attachment-menu-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 8px 4px;
  border-radius: 12px;
  transition: background 0.15s ease;
  animation: attachItemIn 0.25s ease both;
}

.attachment-menu-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.attachment-menu-item:nth-child(1) { animation-delay: 0.03s; }
.attachment-menu-item:nth-child(2) { animation-delay: 0.06s; }
.attachment-menu-item:nth-child(3) { animation-delay: 0.09s; }
.attachment-menu-item:nth-child(4) { animation-delay: 0.12s; }
.attachment-menu-item:nth-child(5) { animation-delay: 0.15s; }
.attachment-menu-item:nth-child(6) { animation-delay: 0.18s; }

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

.attach-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.attachment-menu-item:hover .attach-icon {
  transform: scale(1.1);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.attachment-menu-item span {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  text-align: center;
  line-height: 1.2;
}

/* Icon Colors - per type */
.attach-doc     { background: linear-gradient(135deg, #7c3aed, #6d28d9); }
.attach-photo   { background: linear-gradient(135deg, #ec4899, #db2777); }
.attach-camera  { background: linear-gradient(135deg, #ef4444, #dc2626); }
.attach-audio   { background: linear-gradient(135deg, #f59e0b, #d97706); }
.attach-contact { background: linear-gradient(135deg, #06b6d4, #0891b2); }
.attach-polling { background: linear-gradient(135deg, #10b981, #059669); }

/* Button active state */
.attachment-btn-main.active {
  color: #00a884;
  transform: rotate(45deg);
  transition: transform 0.2s ease, color 0.2s ease;
}

.attachment-btn-main {
  transition: transform 0.2s ease, color 0.2s ease;
}

.message-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

#message-input {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 12px 20px;
  color: var(--text-primary);
  font-size: 14px;
  transition: all var(--transition-base);
}

#message-input::placeholder {
  color: var(--text-muted);
}

#message-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.15);
  background: rgba(26, 26, 46, 0.8);
}

.send-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.send-btn.voice-mode {
  background: var(--bg-tertiary); /* Darker background for mic icon */
}

.send-btn:active:not(:disabled) {
  transform: scale(0.95);
}

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

.send-btn svg {
  transform: translateX(1px);
}

/* === Modal === */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
  padding: 20px;
}

.modal.hidden {
  display: none !important;
}

.modal-content {
  background: var(--bg-secondary);
  border-radius: var(--radius-xl);
  max-width: 440px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
  overflow-y: auto;
}

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

.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

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

.modal-search input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 10px 16px;
  color: var(--text-primary);
  font-size: 13px;
  transition: all var(--transition-base);
}

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

.modal-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Users List */
.users-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  transition: all var(--transition-base);
}

.user-item:hover {
  background: var(--bg-hover);
}

.user-item:active {
  background: var(--accent-soft);
}

.user-item-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
  position: relative;
}

.user-item-avatar .online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: var(--online);
  border: 2px solid var(--bg-secondary);
  border-radius: 50%;
}

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

.user-item-info h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-item-info p {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.users-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  gap: 8px;
}

.users-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.users-loading .loading-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* Mobile-only elements */
.mobile-only {
  display: none;
}

/* ============================================
   KEYFRAME ANIMATIONS
   ============================================ */

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

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

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

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes bounceIn {
  0% {
    opacity: 0;
    transform: scale(0.3);
  }
  50% {
    opacity: 1;
    transform: scale(1.08);
  }
  70% {
    transform: scale(0.95);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes pulseIn {
  0% {
    opacity: 0;
    transform: scale(0.5);
  }
  50% {
    transform: scale(1.15);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* ============================================
   RESPONSIVE — Mobile (max-width: 768px)
   ============================================ */

@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    min-width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 20;
    transition: transform var(--transition-slow);
  }

  #chat-screen.chat-open .sidebar {
    transform: translateX(-100%);
  }

  .chat-area {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    height: 100dvh; /* Dynamic viewport height - shrinks when Android keyboard opens */
    overflow: hidden;
  }

  .chat-view {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .messages-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .message-input-container {
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .mobile-only {
    display: flex;
  }

  .auth-container {
    padding: 28px 24px;
    border-radius: var(--radius-xl);
  }

  .logo-icon {
    font-size: 40px;
  }

  .logo h1 {
    font-size: 24px;
  }

  .message {
    max-width: 80%;
  }

  .messages-container {
    padding: 16px 12px;
  }

  .chat-header {
    padding: 10px 12px;
  }

  .message-input-container {
    padding: 10px 12px max(14px, env(safe-area-inset-bottom));
  }

  .sidebar-header {
    padding: 14px 16px;
  }

  .conversation-item {
    padding: 12px 14px;
  }

  .conversation-avatar {
    width: 44px;
    height: 44px;
    min-width: 44px;
    font-size: 16px;
  }

  .empty-state {
    padding: 30px;
  }

  .empty-icon {
    font-size: 48px;
  }

  .empty-state h2 {
    font-size: 18px;
  }

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

/* Small phones */
@media (max-width: 380px) {
  .auth-container {
    padding: 24px 20px;
  }

  .form-group input {
    padding: 10px 14px;
  }

  .btn-primary {
    padding: 12px;
    font-size: 14px;
  }
}

/* ============================================
   EXTRA POLISH & DETAILS
   ============================================ */

/* Conversation item hover effect */
.conversation-item::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  background: var(--accent);
  opacity: 0;
  transition: opacity var(--transition-base);
}

.conversation-item:hover::after {
  opacity: 0.5;
}

.conversation-item.active::after {
  opacity: 1;
}

/* Smooth transitions on all interactive elements */
input,
button,
.conversation-item,
.user-item {
  transition: all var(--transition-base);
}

/* Focus visible for accessibility */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Prevent text selection on interactive elements */
.auth-tab,
.icon-btn,
.send-btn,
.conversation-item,
.user-item,
.unread-badge {
  user-select: none;
  -webkit-user-select: none;
}

/* Gradient text utility */
.gradient-text {
  background: linear-gradient(135deg, var(--accent), #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Subtle border glow for active elements */
.conversation-item.active {
  box-shadow: inset 0 0 20px rgba(129, 140, 248, 0.05);
}

/* Message bubble hover effects */
.message-bubble {
  transition: transform var(--transition-fast);
}

.message:hover .message-bubble {
  transform: scale(1.01);
}

/* Smooth appear for messages container background */
.messages-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(to bottom, var(--bg-primary), transparent);
  pointer-events: none;
  z-index: 1;
  opacity: 0.8;
}

/* Loading skeleton pulse */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-tertiary) 25%,
    var(--bg-hover) 50%,
    var(--bg-tertiary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

/* Unread badge with pulse */
.unread-badge {
  position: relative;
}

.unread-badge::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  opacity: 0;
  animation: pulse 2s ease-in-out infinite;
  z-index: -1;
}

/* Smooth scroll behavior */
.messages-container,
.conversations-list,
.users-list {
  scroll-behavior: smooth;
}

/* Tooltip styles for icon buttons */
.icon-btn[title] {
  position: relative;
}

.icon-btn[title]:hover::after {
  content: attr(title);
  position: absolute;
  bottom: -32px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 50;
  pointer-events: none;
  animation: fadeIn 0.15s ease;
}

/* Message Dropdown Button */
.msg-dropdown-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--bg-secondary);
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--text-secondary);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
  z-index: 5;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.message.sent .msg-dropdown-btn {
  background: rgba(0,0,0,0.05);
  color: var(--text-secondary);
}

.message:hover .msg-dropdown-btn {
  opacity: 1;
}

.msg-dropdown-btn:hover {
  background: var(--hover);
}
.message.sent .msg-dropdown-btn:hover {
  background: rgba(0,0,0,0.1);
}

/* Global Message Dropdown Menu */
.message-dropdown-menu {
  position: absolute;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 0;
  z-index: 1000;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  min-width: 160px;
}

.message-dropdown-menu.hidden {
  display: none;
}

.message-dropdown-item {
  background: transparent;
  border: none;
  color: #111b21;
  cursor: pointer;
  font-size: 14px;
  padding: 10px 16px;
  text-align: left;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.message-dropdown-item:hover {
  background: #f5f6f6;
}

.message-dropdown-item svg {
  color: #54656f;
}

.message-dropdown-item.danger {
  color: #ef4444;
}
.message-dropdown-item.danger svg {
  color: #ef4444;
}


/* Download Icon Styling */
.media-container {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.download-icon-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border-radius: 50%;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: all 0.3s ease;
  z-index: 10;
  opacity: 0;
}

.media-container:hover .download-icon-btn {
  opacity: 1;
}

.download-icon-btn:hover {
  background: var(--primary);
  transform: scale(1.1);
}

.document-container .download-icon-btn {
  position: static;
  opacity: 1;
  background: transparent;
  color: var(--primary);
  padding: 0;
  margin-left: 10px;
}

.document-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}



/* Media Placeholder Styling */
.media-placeholder {
  background: var(--bg-tertiary);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.3s ease;
}
.media-placeholder:hover {
  background: var(--bg-primary);
  border-color: var(--primary);
  color: var(--primary);
}



/* Blurred Media Styling */
.media-blur-wrapper {
  position: relative;
  display: inline-block;
  cursor: pointer;
  overflow: hidden;
  border-radius: 8px;
}
.blurred-media {
  filter: blur(15px) brightness(0.7);
  transform: scale(1.1);
  transition: all 0.3s ease;
}
.blur-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.5);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}



/* Message Media Sizing */
.message-media {
  max-width: 250px;
  max-height: 250px;
  object-fit: cover;
  border-radius: 8px;
  margin-top: 4px;
  cursor: pointer;
}



/* Custom Dialog Modal */
.custom-dialog-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 60px;
  z-index: 100000;
  animation: fadeIn 0.2s ease;
  /* Scroll if content overflows (Android keyboard) */
  overflow-y: auto;
}

.custom-dialog-box {
  background: #1a2a33;
  border: 1px solid #2a3942;
  border-radius: 16px;
  padding: 20px;
  width: 88%;
  max-width: 400px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  animation: dialogSlideIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  margin-bottom: 20px;
}

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

.custom-dialog-header {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 14px;
  color: #e9edef;
}

.custom-dialog-body {
  font-size: 14px;
  color: #8696a0;
  margin-bottom: 20px;
  line-height: 1.5;
}

.custom-dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.custom-dialog-footer button {
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  min-width: 80px;
  min-height: 44px; /* Better touch target on mobile */
}

.custom-dialog-footer .btn-cancel {
  background: #2a3942;
  color: #8696a0;
}

.custom-dialog-footer .btn-cancel:hover {
  background: #3a4a52;
}

.custom-dialog-footer .btn-confirm {
  background: #00a884;
  color: white;
}

.custom-dialog-footer .btn-confirm:hover {
  background: #008f6f;
}


/* Media Gallery */
.gallery-grid img { width: 100%; height: 100px; object-fit: cover; border-radius: 8px; cursor: pointer; transition: transform 0.2s; }
.gallery-grid img:hover { transform: scale(1.05); }
.gallery-doc-item { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--bg-primary); border-radius: 8px; text-decoration: none; color: var(--text-primary); transition: background 0.2s; border: 1px solid var(--border); }
.gallery-doc-item:hover { background: var(--hover); }

/* Reply & Forward Styles */
#reply-preview-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-primary);
  border-left: 4px solid var(--accent);
  border-radius: 4px 4px 0 0;
  margin-bottom: 2px;
}

.reply-preview-content {
  flex: 1;
  overflow: hidden;
  margin-right: 8px;
}

.message-reply {
  background: rgba(0,0,0,0.05);
  border-left: 4px solid var(--accent);
  padding: 6px 10px;
  border-radius: 4px;
  margin-bottom: 6px;
  cursor: pointer;
}
.message.sent .message-reply { background: rgba(0,0,0,0.05); border-left-color: var(--accent); }

.forwarded-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}
.message.sent .forwarded-label { color: var(--text-muted); }

.forward-contact-item {
  display: flex;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}
.forward-contact-item:hover { background: var(--hover); }
.forward-contact-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-right: 12px;
  cursor: pointer;
}

/* ==========================================
   CONTACT CARD in Chat Bubble
   ========================================== */
.contact-card-bubble {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 168, 132, 0.08);
  border: 1px solid rgba(0, 168, 132, 0.2);
  border-radius: 12px;
  padding: 12px 14px;
  min-width: 200px;
  margin-bottom: 4px;
}

.contact-card-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #06b6d4, #0891b2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.contact-card-info {
  flex: 1;
  min-width: 0;
}

.contact-card-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-card-phone {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.contact-card-email {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* Badge on attach-contact icon when native picker available */
.attach-contact-native::after {
  content: '';
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
}

.attachment-menu-item {
  position: relative;
}

/* ==========================================
   VOICE RECORDING UI
   ========================================== */
.send-btn.voice-mode {
  background: var(--primary); /* WhatsApp uses primary color for mic, accent for send */
  transition: all 0.2s ease;
}

.send-btn.voice-mode:active {
  transform: scale(1.2);
}

.send-btn .mic-icon { display: none; }
.send-btn.voice-mode .mic-icon { display: block; }
.send-btn.voice-mode .send-icon { display: none; }
.send-btn:not(.voice-mode) .mic-icon { display: none; }
.send-btn:not(.voice-mode) .send-icon { display: block; }

.recording-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-radius: 24px;
  z-index: 10;
}

.recording-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
}

.recording-dot {
  width: 10px;
  height: 10px;
  background: #ff3b30;
  border-radius: 50%;
  animation: pulse-red 1.2s infinite;
}

@keyframes pulse-red {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.5; }
  100% { transform: scale(1); opacity: 1; }
}

#recording-timer {
  font-size: 15px;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.cancel-recording-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 50%;
  transition: all 0.2s;
}

.cancel-recording-btn:hover {
  background: var(--bg-hover);
  color: #ff3b30;
}
