/* InstaChat Modern Aesthetics - Multi-Theme & Mobile Viewport Fixed */

:root {
  /* Default: InstaDark Theme */
  --bg-dark: #0b1120;
  --bg-card: #151e32;
  --bg-card-hover: #1e2d4a;
  --bg-input: #1a263e;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-active: rgba(255, 255, 255, 0.18);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  
  --primary-wa: #10b981;
  --primary-wa-hover: #059669;
  --primary-wa-alpha: rgba(16, 185, 129, 0.15);
  
  --ig-grad: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
  --ig-pink: #e1306c;
  
  --bubble-out: #059669;
  --bubble-in: #1e293b;
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.4);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* THEME 2: WhatsApp Emerald Dark */
body.theme-whatsapp {
  --bg-dark: #0b141a;
  --bg-card: #111b21;
  --bg-card-hover: #202c33;
  --bg-input: #2a3942;
  --border-color: rgba(255, 255, 255, 0.06);
  --primary-wa: #00a884;
  --primary-wa-hover: #008f70;
  --primary-wa-alpha: rgba(0, 168, 132, 0.15);
  --bubble-out: #005c4b;
  --bubble-in: #202c33;
}

/* THEME 3: Instagram Neon Violet */
body.theme-instagram {
  --bg-dark: #0f051d;
  --bg-card: #1c0b36;
  --bg-card-hover: #2e1254;
  --bg-input: #260f47;
  --border-color: rgba(225, 48, 108, 0.15);
  --primary-wa: #e1306c;
  --primary-wa-hover: #c1285d;
  --primary-wa-alpha: rgba(225, 48, 108, 0.2);
  --bubble-out: #833ab4;
  --bubble-in: #2a124d;
}

/* THEME 4: Cyberpunk Neon */
body.theme-cyberpunk {
  --bg-dark: #050814;
  --bg-card: #0c1226;
  --bg-card-hover: #182245;
  --bg-input: #121c3b;
  --border-color: rgba(6, 182, 212, 0.2);
  --primary-wa: #06b6d4;
  --primary-wa-hover: #0891b2;
  --primary-wa-alpha: rgba(6, 182, 212, 0.2);
  --bubble-out: #0284c7;
  --bubble-in: #1e1b4b;
}

/* THEME 5: Clean Light Mode */
body.theme-light {
  --bg-dark: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-input: #e2e8f0;
  --border-color: rgba(0, 0, 0, 0.08);
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;
  --primary-wa: #059669;
  --primary-wa-hover: #047857;
  --primary-wa-alpha: rgba(5, 150, 105, 0.12);
  --bubble-out: #059669;
  --bubble-in: #e2e8f0;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
}

/* THEME 6: Midnight Violet */
body.theme-midnight-violet {
  --bg-dark: #0a0612;
  --bg-card: #150d26;
  --bg-card-hover: #23163d;
  --bg-input: #1c1133;
  --border-color: rgba(168, 85, 247, 0.25);
  --primary-wa: #a855f7;
  --primary-wa-hover: #9333ea;
  --primary-wa-alpha: rgba(168, 85, 247, 0.2);
  --bubble-out: #7e22ce;
  --bubble-in: #2e1065;
}

/* THEME 7: Sunset Gold */
body.theme-sunset-gold {
  --bg-dark: #120b05;
  --bg-card: #24160a;
  --bg-card-hover: #382210;
  --bg-input: #2d1b0d;
  --border-color: rgba(245, 158, 11, 0.25);
  --primary-wa: #f59e0b;
  --primary-wa-hover: #d97706;
  --primary-wa-alpha: rgba(245, 158, 11, 0.2);
  --bubble-out: #ea580c;
  --bubble-in: #451a03;
}

/* THEME 8: Matrix Hacker Green */
body.theme-matrix-green {
  --bg-dark: #020d06;
  --bg-card: #061a0e;
  --bg-card-hover: #0c2e19;
  --bg-input: #092413;
  --border-color: rgba(34, 197, 94, 0.25);
  --primary-wa: #22c55e;
  --primary-wa-hover: #16a34a;
  --primary-wa-alpha: rgba(34, 197, 94, 0.2);
  --bubble-out: #15803d;
  --bubble-in: #052e16;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: var(--font-family);
  -webkit-font-smoothing: antialiased;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  background-color: var(--bg-dark);
  color: var(--text-main);
}

body:not(.auth-body) {
  overflow: hidden;
}

/* ==========================================================================
   AUTH PAGES (Scrollable & Responsive)
   ========================================================================== */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  overflow-y: auto;
  background: radial-gradient(circle at top right, rgba(16, 185, 129, 0.12), transparent 40%),
              radial-gradient(circle at bottom left, rgba(225, 48, 108, 0.12), transparent 40%),
              var(--bg-dark);
  padding: 40px 16px;
}

.auth-container {
  width: 100%;
  max-width: 460px;
  max-height: calc(100dvh - 60px);
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(16px);
  margin: auto;
}

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

.brand-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 2.2rem;
  margin-bottom: 8px;
}

.logo-icon-ig {
  background: var(--ig-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-icon-wa {
  color: var(--primary-wa);
}

.auth-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.auth-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.auth-tabs {
  display: flex;
  background: var(--bg-input);
  padding: 4px;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
}

.auth-tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.auth-tab-btn.active {
  background: var(--bg-card);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

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

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

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

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.form-group input, .form-group textarea, .form-group select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  border-color: var(--primary-wa);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--primary-wa);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-wa-hover);
}

.btn-block {
  width: 100%;
}

.auth-footer {
  margin-top: 24px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-subtle);
}

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.alert-success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #6ee7b7;
}

.hidden {
  display: none !important;
}

.avatar-upload-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.avatar-circle {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid var(--primary-wa);
  overflow: visible;
}

.avatar-circle img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.avatar-edit-badge {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 28px;
  height: 28px;
  background: var(--primary-wa);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  cursor: pointer;
  border: 2px solid var(--bg-card);
}

.hidden-input {
  display: none;
}

.avatar-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

/* 3D PRESET AVATAR SELECTION GRID */
.preset-avatar-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
  padding: 4px;
}

.preset-avatar-item {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--bg-input);
  flex-shrink: 0;
}

.preset-avatar-item img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.preset-avatar-item:hover, .preset-avatar-item.selected {
  border-color: var(--primary-wa);
  transform: scale(1.12);
  box-shadow: 0 0 14px var(--primary-wa-alpha);
}

/* ==========================================================================
   MAIN APPLICATION DASHBOARD
   ========================================================================== */
.app-container {
  display: flex;
  width: 100vw;
  height: 100dvh;
  background-color: var(--bg-dark);
  position: relative;
  overflow: hidden;
}

/* SIDEBAR PANEL */
.sidebar-panel {
  width: 400px;
  min-width: 320px;
  background-color: var(--bg-card);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 10;
  position: relative;
}

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

.user-profile-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--text-main);
  text-align: left;
}

.user-avatar-small {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.user-name-title {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.2;
}

.user-status-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

/* INSTAGRAM STORIES TRAY */
.stories-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.1);
}

.stories-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-subtle);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stories-tray {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.story-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  flex-shrink: 0;
  width: 64px;
}

.story-ring {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  padding: 3px;
  background: var(--border-color);
  transition: transform 0.2s ease;
}

.story-item.unseen .story-ring {
  background: var(--ig-grad);
}

.story-ring img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--bg-card);
}

.story-item:hover .story-ring {
  transform: scale(1.05);
}

.story-add-badge {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 20px;
  height: 20px;
  background: var(--primary-wa);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  border: 2px solid var(--bg-card);
}

.story-username {
  font-size: 0.75rem;
  color: var(--text-muted);
  max-width: 60px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

/* SEARCH & CHAT FILTER TABS */
.search-container {
  padding: 12px 16px;
}

.search-input-wrap {
  position: relative;
}

.search-input-wrap i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
}

.search-input-wrap input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px 10px 38px;
  color: var(--text-main);
  font-size: 0.88rem;
  outline: none;
}

.chat-filter-tabs {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px 16px;
  border-bottom: 1px solid var(--border-color);
}

.filter-chip {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-chip.active {
  background: var(--primary-wa-alpha);
  border-color: var(--primary-wa);
  color: var(--primary-wa);
}

/* CHATS LIST AREA */
.chats-list-container {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s ease;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.chat-item:hover, .chat-item.active {
  background: var(--bg-card-hover);
}

.chat-avatar-wrap {
  position: relative;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.chat-avatar-wrap img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.online-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  background: var(--primary-wa);
  border: 2px solid var(--bg-card);
  border-radius: 50%;
}

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

.chat-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.chat-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-time {
  font-size: 0.75rem;
  color: var(--text-subtle);
}

.chat-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-snippet {
  font-size: 0.84rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.unread-badge {
  background: var(--primary-wa);
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* FLOATING ACTION BUTTON (MOBILE) */
.mobile-fab-btn {
  display: none;
  position: absolute;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary-wa);
  color: white;
  border: none;
  box-shadow: var(--shadow-lg);
  font-size: 1.4rem;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
}

/* ==========================================================================
   WEBRTC VOICE & VIDEO CALLING STYLES
   ========================================================================== */
.call-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200000;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.call-modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.call-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0b0f19;
  overflow: hidden;
}

.remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.call-avatar-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #fff;
  z-index: 5;
}

.call-avatar-fallback img {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid var(--primary-wa);
  box-shadow: 0 0 30px rgba(16, 185, 129, 0.4);
  animation: pulse 2s infinite;
}

.local-video-pip {
  position: absolute;
  top: 24px;
  right: 24px;
  width: 140px;
  height: 190px;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  z-index: 20;
  background: #111;
}

.local-video-pip video {
.call-profile-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 10;
  color: #fff;
}

.incoming-action-group {
  position: absolute;
  bottom: 50px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 50px;
  z-index: 30;
}

.incoming-action-group.hidden,
.call-controls-bar.hidden {
  display: none !important;
}

.call-controls-bar {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 24px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(16px);
  border-radius: 40px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  z-index: 30;
}

.call-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  font-size: 1.25rem;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.call-btn.btn-mute { background: rgba(255, 255, 255, 0.15); }
.call-btn.btn-mute.active { background: #f59e0b; }
.call-btn.btn-cam { background: rgba(255, 255, 255, 0.15); }
.call-btn.btn-cam.active { background: #64748b; }
.call-btn.btn-switch { background: rgba(255, 255, 255, 0.15); }
.call-btn.btn-switch:hover { background: rgba(255, 255, 255, 0.3); transform: scale(1.08); }
.call-btn.btn-speaker { background: rgba(255, 255, 255, 0.15); }
.call-btn.btn-speaker.active { background: #10b981; }
.call-btn.btn-end { background: #ef4444; }
.call-btn.btn-end:hover { transform: scale(1.1); background: #dc2626; }

/* INCOMING CALL BANNER */
.incoming-call-banner {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100001;
  width: 90%;
  max-width: 420px;
  background: var(--bg-card);
  border: 2px solid var(--primary-wa);
  border-radius: 20px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7);
  animation: slideDown 0.4s ease;
}

.incoming-call-banner img {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  object-fit: cover;
}

.call-action-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  font-size: 1.1rem;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.call-action-btn.btn-accept { background: #10b981; }
.call-action-btn.btn-reject { background: #ef4444; }
.call-action-btn:hover { transform: scale(1.1); }

/* FULL-SCREEN WHATSAPP INCOMING CALL OVERLAY MODAL */
.incoming-call-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100005;
  background: rgba(11, 15, 25, 0.95);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.incoming-call-modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.incoming-call-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: #fff;
  padding: 30px;
}

.caller-avatar-pulse {
  position: relative;
  width: 120px;
  height: 120px;
}

.caller-avatar-pulse img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid var(--primary-wa);
  box-shadow: 0 0 35px var(--primary-wa-alpha);
  animation: pulse 1.8s infinite;
}

.incoming-modal-actions {
  display: flex;
  align-items: center;
  gap: 40px;
  margin-top: 40px;
}

.incoming-modal-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.incoming-modal-btn i {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  transition: transform 0.2s ease;
}

.incoming-modal-btn.btn-decline i { background: #ef4444; }
.incoming-modal-btn.btn-answer i { background: #10b981; animation: bounce 1.2s infinite; }
.incoming-modal-btn:hover i { transform: scale(1.15); }

/* CHAT MENU DROPDOWN */
.chat-dropdown-menu {
  position: absolute;
  top: 50px;
  right: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 0;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  z-index: 99;
  min-width: 180px;
  animation: fadeIn 0.2s ease;
}

.chat-dropdown-menu .menu-item {
  padding: 10px 16px;
  font-size: 0.88rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.chat-dropdown-menu .menu-item:hover {
  background: var(--bg-input);
  color: var(--primary-wa);
}

/* IN-CHAT MESSAGE SEARCH BAR */
.in-chat-search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  animation: slideDown 0.2s ease;
}

.in-chat-search-bar input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 6px 14px;
  color: var(--text-main);
  font-size: 0.88rem;
  outline: none;
}

/* QUOTED REPLY BOX & PREVIEW BAR */
.reply-preview-bar {
  padding: 8px 16px;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.quoted-reply-box {
  background: rgba(255, 255, 255, 0.08);
  border-left: 3px solid var(--primary-wa);
  border-radius: 4px;
  padding: 4px 8px;
  margin-bottom: 6px;
  font-size: 0.8rem;
}

.quoted-reply-box .quoted-author {
  font-weight: 700;
  color: var(--primary-wa);
}

.quoted-reply-box .quoted-text {
  color: var(--text-subtle);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pin-badge {
  color: var(--primary-wa);
  font-size: 0.75rem;
  margin-left: 4px;
}

/* ==========================================================================
   CHAT MESSAGING MAIN AREA
   ========================================================================== */
.chat-main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg-dark);
  position: relative;
  overflow: hidden;
}

.no-chat-selected {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}

.no-chat-selected i {
  font-size: 4rem;
  margin-bottom: 16px;
  color: var(--primary-wa);
}

.no-chat-selected h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
}

.no-chat-selected p {
  font-size: 0.9rem;
  color: var(--text-subtle);
  max-width: 320px;
}

/* Active Chat Top Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  z-index: 20;
  flex-shrink: 0;
}

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

.back-btn-mobile {
  display: none;
}

.header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
}

.header-title {
  font-weight: 700;
  font-size: 1rem;
}

.header-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Messages Stream */
.messages-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message-bubble {
  max-width: 75%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  word-wrap: break-word;
  animation: fadeIn 0.15s ease-in-out;
}

.message-bubble.incoming {
  align-self: flex-start;
}

.message-bubble.outgoing {
  align-self: flex-end;
}

.message-content {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  line-height: 1.4;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.incoming .message-content {
  background-color: var(--bubble-in);
  color: var(--text-main);
  border-top-left-radius: 2px;
}

.outgoing .message-content {
  background-color: var(--bubble-out);
  color: white;
  border-top-right-radius: 2px;
}

.sender-name-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary-wa);
  margin-bottom: 2px;
}

.message-media {
  max-width: 100%;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  cursor: pointer;
}

.audio-msg-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}

.audio-play-btn {
  background: white;
  color: var(--bubble-out);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  cursor: pointer;
}

.incoming .audio-play-btn {
  background: var(--primary-wa);
  color: white;
}

.reactions-pill-bar {
  display: flex;
  gap: 4px;
  margin-top: -6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 2px 6px;
  border-radius: 12px;
  font-size: 0.75rem;
  width: fit-content;
  box-shadow: var(--shadow-sm);
}

.incoming .reactions-pill-bar { align-self: flex-start; }
.outgoing .reactions-pill-bar { align-self: flex-end; }

.quick-react-trigger {
  opacity: 0;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  transition: opacity 0.2s ease;
  cursor: pointer;
}

.incoming .quick-react-trigger { right: -32px; }
.outgoing .quick-react-trigger { left: -32px; }

.message-bubble:hover .quick-react-trigger {
  opacity: 1;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  font-size: 0.7rem;
  opacity: 0.8;
  margin-top: 4px;
}

/* Chat Input Bar - FIXED MOBILE VISIBILITY */
.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  position: sticky;
  bottom: 0;
  width: 100%;
  z-index: 30;
  box-sizing: border-box;
}

.input-field-wrap {
  flex: 1;
  position: relative;
}

.input-field-wrap input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 12px 18px 12px 42px;
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
}

.emoji-trigger-btn {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
}

.send-btn {
  background: var(--primary-wa);
  color: white;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.send-btn:hover {
  transform: scale(1.05);
  background: var(--primary-wa-hover);
}

.record-mic-btn {
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.record-mic-btn.recording {
  background: #ef4444;
  color: white;
  animation: pulse 1s infinite;
}

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

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.emoji-picker-popup {
  position: absolute;
  bottom: 70px;
  left: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 40;
  font-size: 1.3rem;
}

.emoji-picker-popup span {
  cursor: pointer;
  text-align: center;
  padding: 4px;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.emoji-picker-popup span:hover {
  background: var(--bg-card-hover);
}

/* ==========================================================================
   MODALS
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 92%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  padding: 24px;
  position: relative;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h3 {
  font-size: 1.2rem;
  font-weight: 700;
}

.theme-options-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 6px;
}

.theme-card {
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-color);
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-card.active {
  border-color: var(--primary-wa);
  background: var(--primary-wa-alpha);
}

/* FULLSCREEN INSTAGRAM STORY VIEWER MODAL */
.story-viewer-modal {
  width: 100%;
  max-width: 420px;
  height: 85dvh;
  max-height: 720px;
  background: #000;
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.story-progress-bar-wrap {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  gap: 4px;
  z-index: 10;
}

.story-progress-seg {
  flex: 1;
  height: 3px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  overflow: hidden;
}

.story-progress-fill {
  width: 0%;
  height: 100%;
  background: white;
}

.story-header-overlay {
  position: absolute;
  top: 24px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
  color: white;
}

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

.story-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.story-content-display {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background-size: cover;
  background-position: center;
}

.story-content-display img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.story-text-only {
  padding: 30px;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: white;
}

.story-caption-overlay {
  position: absolute;
  bottom: 24px;
  left: 12px;
  right: 12px;
  background: rgba(0, 0, 0, 0.6);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 0.9rem;
  text-align: center;
}

.story-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.3);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
}

.story-nav-btn.prev { left: 10px; }
.story-nav-btn.next { right: 10px; }

.contact-select-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 220px;
  overflow-y: auto;
  margin-top: 10px;
}

.contact-select-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.contact-select-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary-wa);
}

/* ==========================================================================
   MOBILE SPECIFIC OVERRIDES (< 768px)
   ========================================================================== */
@media (max-width: 768px) {
  html, body {
    height: 100%;
    height: -webkit-fill-available;
  }

  .app-container {
    height: 100%;
    height: -webkit-fill-available;
  }

  .sidebar-panel {
    width: 100%;
    height: 100%;
  }

  .mobile-fab-btn {
    display: flex;
  }

  .chat-main-panel {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100%;
    height: 100dvh;
    height: -webkit-fill-available;
    z-index: 9999;
    background: var(--bg-dark);
  }

  .chat-main-panel.mobile-active {
    display: flex;
    flex-direction: column;
  }

  #activeChatScreen {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    flex: 1;
    overflow: hidden;
  }

  .chat-header {
    flex-shrink: 0;
  }

  .messages-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .chat-input-bar {
    position: relative;
    width: 100%;
    flex-shrink: 0;
    z-index: 10000;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .back-btn-mobile {
    display: flex;
  }

  .message-bubble {
    max-width: 85%;
  }

  .theme-options-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
